note 24816 added to function.fflush

From: Date: Thu, 29 Aug 2002 05:56:15 +0000
Subject: note 24816 added to function.fflush
Groups: php.notes 
Request: Send a blank email to php-notes+get-35964@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. -- http://www.php.net/manual/en/function.fflush.php http://master.php.net/manage/user-notes.php?action=edit+24816 http://master.php.net/manage/user-notes.php?action=delete+24816 http://master.php.net/manage/user-notes.php?action=reject+24816

« previous php.notes (#35964) next »