note 55881 deleted from function.fpassthru by victor
| From: | victor@php.net | Date: | Tue, 16 Aug 2005 14:45:23 +0000 |
| Subject: | note 55881 deleted from function.fpassthru by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93743@lists.php.net to get a copy of this message | ||
Note Submitter: suplado_calan
----
<?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.