You are here: Re: readfile_and_downloads « PHP Programming Language « IT news, forums, messages
Re: readfile_and_downloads

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация