Re: Problem with file download/fopen/fread
| From: | (Alex Elderson) | Date: | Tue, 02 Jul 2002 13:02:36 +0000 |
| Subject: | Re: Problem with file download/fopen/fread | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-14526@lists.php.net to get a copy of this message | ||
Hi,
I have the same problem
Mail me if you have an idee (alex@netflex.nl)
if (!($fc = fopen($base_path . $path . $file, "rb"))) {
echo "error\n";
exit;
}
$file_size = filesize($base_path . $path . $file);
ob_end_clean();
ignore_user_abort(false);
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
// IE cannot download from sessions without a cache
header('Cache-Control: public');
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment;
filename=\"".$file."\"");
header("Content-length: ".(string)($file_size));
if ($description!="") {
header("Content-Description: " . $description);
}
while(!feof($fc)) {
set_time_limit(5);
echo fread($fc, 10240);
flush();
}
fclose($fc);
exit;
In article <20020619202210.96898.qmail@pb1.pair.com>, dariusz@bulgaria.com says...
>
>
>OS: WinXP Pro
>Apache 2.0.36
>PHP 4.2.1 (module)
>
>
>A simple script:
>
>$f = "e:/web/old.zip";
>header("Content-type: application/zip");
>header("Content-Disposition: attachment; filename=old.zip");
>header("Content-Length: " . filesize($f));
>$fp = fopen($f, "rb");
>if (!$fp) exit("FILE ERROR");
>while (!feof($fp))
>{
> print fread($fp, 4096);
>}
>fclose($fp);
>
>
>The first ~8kB of the downloaded file are OK but from then on the downloaded
>file is totally screwed up, the filesize is correct though.
>With small files it seems to work fine (the one above is ~11MB).
>
>Also tried with readfile(..) and with fpassthru(..), doesn't work either.
>
>Anyone encountered similar problems or even better: has a solution to this?
>
>-- Dariusz
>
>
>