开发者

Content Dispostion header set in PHP not working with Firefox

I have a form button that submits the data to generic scri开发者_运维百科pt (the same page that the form is loaded from, index.php) and if the right POST variables are submitted to that script, it returns a PDF for the user to print (with the relevant form info loaded, and other DB info, etc).

The problem is that no matter what I set the content-type and the content-disposition to in the header, Firefox prompts the user to either save or open the document.

This wouldn't be so bad if Firefox offered it's own Adobe Reader plugin as an "Open With" option, but it only offers the actual Adobe Reader App (which causes problems due to authentication and default browser settings being out of my control, etc).

So is there something server side I need to change (either in the .htaccess file or in the actual header) to have Firefox get the message that response is both a PDF with the application/pdf MIME Type and thus should treat the file as though it were a hard link to a PDF, not a server-generated stream?

One last thing...

If I set the Content-Disposition to "inline" Firefox opens the file in Firefox, but only before loading the page as "index.php" first. Once the user gets to the PDF, if they try clicking the back button, they hit the index.php that loaded the PDF, not the one that they submitted the data. On the Mac side of things, Firefox doesn't load the PDF but instead prompts the user to save or open "index.php" as though it were an attachment.

Thanks!


Currently the code I've tried (in this order):

This one gets treated as a file attachment, thus the Mime-Type rule for Firefox is ignored for the file extension rule:

    header("Content-Type: application/pdf");
    header('Content-Disposition:attachment; filename="testing.pdf"');

This one works but loads index.php first and then loads the file, which is unattractive, confusing, and puts an extra request (and thus an extra page) between the pdf and the original page:

    header("Content-Type: application/pdf");
    header('Content-Disposition:inline; filename="testing.pdf"');

This one gets treated the same as attachment (in Firefox) and thus only prompts to save or open in Adobe Reader rather than defaulting to Adobe Reader plugin:

    header("Content-Type: application/pdf");
    header('Content-Disposition:pdf; filename="testing.pdf"');

Also notice that in the last example I have tried both pdf and application\pdf as the content disposition. No difference.

The only thing I haven't tried yet is setting the type as ocet/stream. I'll cross my fingers but won't hold my breath.


You could try having the link end in ".pdf", and use something like mod_rewrite to map it to your PHP script.


I'm thinking that Firefox is having a hard time handling the PDF as a response to a POST, could you try generating a link to the PDF and having them click on the link, the link could contain GET variables like blah.php?VAR=123 so you can still dynamically generate the PDF.


The mime-type application/octet-stream should force the browser to download it. I can't tell if that's what you want from your post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜