tonye Posted May 20, 2014 Share Posted May 20, 2014 <?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 34Warning: filesize() [function.filesize]: stat failed for images/unavailable.png in C:\xampp\htdocs\mail\show_image.php on line 35Warning: 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 38Warning: 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 39Warning: 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 40Warning: 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 More sharing options...
HartleySan Posted May 20, 2014 Share Posted May 20, 2014 The file you're pointing to doesn't exist. You're outputting whitespace or something to the browser before the header function calls. Fix both of those, and it should work (or you'll at least be close). 1 Link to comment Share on other sites More sharing options...
Larry Posted May 26, 2014 Share Posted May 26, 2014 The error message created by 1 (the file not existing) is what's causing 2 (the other issues). Fix 1 and you'll automatically fix 2. Link to comment Share on other sites More sharing options...
Sylva Posted June 28, 2014 Share Posted June 28, 2014 Larry in terms of the getimagesize that is used for image which one can I use to validate other files like pdfs Link to comment Share on other sites More sharing options...
Larry Posted June 30, 2014 Share Posted June 30, 2014 You'd use the Fileinfo extension, which I believe I also discuss in the book. Link to comment Share on other sites More sharing options...
silegav Posted July 10, 2014 Share Posted July 10, 2014 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 More sharing options...
Larry Posted July 10, 2014 Share Posted July 10, 2014 Thanks for sharing that! Excellent debugging work and I really appreciate you letting others know what you figured out. Link to comment Share on other sites More sharing options...
Recommended Posts