|
Posted by Sean on 10/29/71 11:33
Something like this would work, you have to put some logging features
in.
function download_file($filename, $content_type =
'application/octet-stream', $isDel=false)
{
$file=basename($filename);
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
$file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') -
1);
}
// make sure the file exists before sending headers
if(!$fdl=@fopen($filename,'r'))
{
die("<br>Cannot Open File!<br>");
}
else
{
header("Cache-Control: ");// leave blank to avoid IE errors
header("Pragma: ");// leave blank to avoid IE errors
header("Content-type: $content_type");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-length:".(string)(filesize($filename)));
sleep(1);
fpassthru($fdl);
}
if($isDel)
{
@unlink($filename);
}
}
download_file('./test.csv');
That should work across fire fox and ie (I don't know about safari or
opera). And the code can be tidied up a bit.
I think processing only chucks of a file at a time code get very
unnecessarily complex. If you are worried about performance why not set
up your downloads as torrents?
Navigation:
[Reply to this message]
|