note 24816 rejected from function.fflush by spic
| From: | spic@php.net | Date: | Thu, 29 Aug 2002 13:54:01 +0000 |
| Subject: | note 24816 rejected from function.fflush by spic | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-35984@lists.php.net to get a copy of this message | ||
To westbx@volny.cz:
Your code sample is incorrect. I refer you to the fpassthru manual page:
"The file is closed when fpassthru() is done reading it (leaving fp useless)."
Thus, you don't need to use fflush() at all in this instance. If you ARE using fflush() with
another file pointer, you need to hand the fflush() function a file pointer handle, as in:
fflush($fp);
The corrected code should look like this:
// Displaying a JPG image
$fp=fopen($path_to_file, "rb");
/* $path_to_file is the full path to the file, e.g. "/home/username/htdocs/image.jpg" */
$filename = basename($path_to_file);
// gives the file name, e.g. image.jpg
header( "Content-type: image/jpeg\nContent-Disposition: inline;
filename=\"$filename\"\nContent-length: ".(string)(filesize($path_to_file)) );
fpassthru($fp);
That should handle displaying images through PHP.