note 29162 added to function.fpassthru

From: Date: Tue, 04 Feb 2003 20:49:40 +0000
Subject: note 29162 added to function.fpassthru
Groups: php.notes 
Request: Send a blank email to php-notes+get-43412@lists.php.net to get a copy of this message
The above method worked for me after trying everything else imaginable to get Explorer to download a file via PHP. However, I had to change the content-length line. No need to "stringify" the $size variable as in the above post. The method below works for both small and very large file (tested on files larger than 30MB with no probs)... <?php $distribution="/path/to/a/file.exe" if ($fd = fopen ($distribution, "r")){ $size=filesize($distribution); $fname = basename ($distribution); //This is some really weak code I used just to redirect to the file before I fixed //this problem...it makes the browser handle the download via Apache instead of PHP //but it would be really easy to then find out the true location of the file //header("Location: $distribution"); //fclose ($fd); //exit; //below is a much better way to do it... header("Pragma: "); header("Cache-Control: "); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$fname."\""); header("Content-length: $size"); while(!feof($fd)) { $buffer = fread($fd, 2048); print $buffer; } fclose ($fd); exit; } ?> Good luck. Brett Brewer. -- http://www.php.net/manual/en/function.fpassthru.php http://master.php.net/manage/user-notes.php?action=edit+29162 http://master.php.net/manage/user-notes.php?action=delete+29162 http://master.php.net/manage/user-notes.php?action=reject+29162

« previous php.notes (#43412) next »