note 55881 added to function.fpassthru
| From: | suplado_calan at osu1 dot php dot net | Date: | Tue, 16 Aug 2005 14:16:19 +0000 |
| Subject: | note 55881 added to function.fpassthru | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93741@lists.php.net to get a copy of this message | ||
<?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.
----
Manual Page -- http://www.php.net/manual/en/function.fpassthru.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55881
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55881&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55881&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55881&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55881&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55881&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55881&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55881&report=yes
Search -- http://master.php.net/manage/user-notes.php