I think you might need a space after attachment;
:
header("Content-Disposition: attachment; filename=$filename");
If that doesn't work, check out some of the points in this article, including:
- On IE 6.0, things mostly work, but if you ALSO setup Cache-Control: no-cache, your suggested filename (and type!) will be IGNORED. A bummer if you have to choose between security and convienence. Of course, security wins.
- On nearly all versions of IE, including 6.0, sometimes the browser will use the filename in the address bar instead of the Content-Disposition Header, and with IE5.5SP2 you're expected to change the UseCDFileName registry key, see Q303750. This was fixed with IE6.0SP1.
EDIT: Here's the code I use, directly copied from my application's source. Let me know if this works any better...
function forceDownload($filename,$mime=false,$downloadName=false)
{
if(file_exists($filename) && is_readable($filename))
{
if(!$mime) $mime = DFStdLib::determineMimeType($filename);
if(!$expire) $expire = DFStdLib::HOUR_IN_SECONDS;
if(!$downloadName) $downloadName = basename($filename);
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT', true, 200);
header('Cache-Control: no-cache',true);
header('Pragma: Public',true);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT',true);
header('Content-Length: '.filesize($filename),true);
header("Content-Type: {$mime}",true);
header("Content-disposition: attachment; filename=$downloadName",true);
readfile($filename);
exit();
}
else
{
header('HTTP/1.1 404 Not Found',true,404);
echo "<html><head><title>Not Found</title></head><body>The file was not found.</body></html>";
exit();
}
}
Usage for your case would be:
forceDownload('/example.pdf','application/pdf','quickquote.pdf');
Also you'll need to change DFStdLib::HOUR_IN_SECONDS
to 3600
and write your own determineMimeType
function, or delete that line and make the $mime
argument required...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…