views:

91

answers:

3

I am generating dynamic PDF reports in PHP and having some issues with links to the web.

My links are to a PHP script that forces the download of a file attachment. This script works perfectly in all browser when accessed via the browser. It also works from the PDF in all browser except Internet Explorer.

Instead of IE seeing the file as a PDF, PNG, or whatever the file is, the download prompt says the document type is: "HTML Plugin Document"

If the user clicks "Open" or "Save" IE says it cannot download the file and gives the filename as "index2.php". That is the beginning of the URI of address.

The correct filesize is given so I know it is getting the file. Maybe it is a header issue?

Here is the header I'm creating on the download script:

            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT;");
 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT;");
 header("Pragma: no-cache;");        // HTTP/1.0
 header('Content-Type: '.$file->file_mime_type.';');
 header("Content-Description: File Transfer");
 header("Cache-Control: public");
            header('Content-Disposition: attachment; filename="'.$file->file_name.'";');
 header('Content-Length: '.$file->file_size.';');
 header('Content-transfer-encoding: binary');

Any input would be greatly appreciated.

+5  A: 

have you tried something like this?

header('Content-Disposition: attachment; filename="'.$file->filename.'"');
Scott Anderson
yes, forgot to paste that with my code...sorry about that.
ws0x9
are you passing a mime-type of "application/pdf" ?
Scott Anderson
for pdf's yes.Files can be pdf, png, jpeg, zip, or doc.None of them are working as of now in IE through the PDF only.
ws0x9
+5  A: 

Here's what I use and that is proven to work:

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="report.pdf"');
readfile($filename);
sanmai
sanmai, did it.I was using PHP's:file_get_contentsinstead of:ob_clean();flush();readfile($the_file);Thank you all for the help.
ws0x9
+3  A: 

It might be worth mentioning that there is also a known issue on several versions of IE when transferring files over SSL which requires the following work around:

header("Cache-Control: maxage=1");
header("Pragma: public");

There is more information regarding this bug here: http://support.microsoft.com/kb/812935

evolve