Jump to content
Larry Ullman's Book Forums

Recommended Posts

<?php # Script 10.5 - show_image.php
// This page displays an image.
 
$name = FALSE; // Flag variable:
 
// Check for an image name in the URL:
if (isset($_GET['image'])) {
 
// Full image path:
$image = "../uploads/{$_GET['image']}";
 
// Check that the image exists and is a file:
if (file_exists ($image) && (is_file($image))) {
 
// Make sure it has an image's extension:
$ext = strtolower ( substr ($_GET['image'], -4));
 
if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) {
// Set the name as this image:
$name = $_GET['image'];
} // End of $ext IF.
 
} // End of file_exists() IF.
 
} // End of isset($_GET['image']) IF.
 
// If there was a problem, use the default image:
if (!$name) {
$image = 'images/unavailable.png';
$name = 'unavailable.png';
}
 
// Get the image information:
$inf =  getimagesize($image);
$fs = filesize($image);
 
// Send the content information:
header ("Content-Type: {$info['mime']}\n");
header ("Content-Disposition: inline; filename=\"$name\"\n");
header ("Content-Length: $fs\n");
 
// Send the file:
readfile ($image);
 
?>
 
after i run the code on my browser all i see this.
 
 
Warning: getimagesize(images/unavailable.png) [function.getimagesize]: failed to open stream: No such file or directory in C:\xampp\htdocs\mail\show_image.php on line 34

Warning: filesize() [function.filesize]: stat failed for images/unavailable.png in C:\xampp\htdocs\mail\show_image.php on line 35

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mail\show_image.php:34) in C:\xampp\htdocs\mail\show_image.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mail\show_image.php:34) in C:\xampp\htdocs\mail\show_image.php on line 39

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mail\show_image.php:34) in C:\xampp\htdocs\mail\show_image.php on line 40

Warning: readfile(images/unavailable.png) [function.readfile]: failed to open stream: No such file or directory in C:\xampp\htdocs\mail\show_image.php on line 43
 
And have created the function for this..
Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

hello to everyone in forum from wonderful Greece

I dealted the same problem and after 10 hours tries to find what is the fault.....i found it....

I use dreamweaver to write php code, so the fault was all the html tags

I had read on larry's book that it is forbidden to write any html code on php script show_image, and i didnt write.

The problem caused by the default html code that dreamweaver document had.So erase everything in document, erase the body tags, everything, and just write only pure php code...and it will be work!!!
(SORRY FOR MY BAD ENGLISH) 

Link to comment
Share on other sites

 Share

×
×
  • Create New...