[_] Content Disposition Header
Richard Davey
rich at corephp.co.uk
Thu Oct 4 15:52:30 BST 2007
Hi nik,
Thursday, October 4, 2007, 2:52:10 PM, you wrote:
> Quick question for the PHP peeps out there... I'm trying to force a
> download of a PDF, and it's working fine on a mac, and in FF on a PC
> - but IE is returning the following:
> <?php
> header('Content-type: application/pdf');
> header('Content-Disposition: attachment; filename="my_file.pdf"');
> readfile('my_file.pdf');
?>>
For IE I'd force this content-type:
header('Content-Type: application/octet-stream');
header("Content-Length: $filesize");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
fpassthru($fp);
fclose($fp);
exit;
I'd recommend fpassthru as well, especially for large / popular files.
For common file types (jpg, gif, zip, etc) I'll use that Content-Type
explicitly, but IE and PDFs have given me enough grief in the past to
have to resort to the infamous 'octet-stream'.
Cheers,
Rich
--
Zend Certified Engineer
http://www.corephp.co.uk
"Never trust a computer you can't throw out of a window"