8

So, I have a file that sends the following:

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private");
header("Content-type: application/pdf");
header("Content-disposition: inline; filename=file.pdf");
header("Content-length: 7735");

then I echo out the file - it is a PDF file.

Works fine in IE6 & 7 on XP (and FF for that matter) The very same code shows nothing when running on IE8 on either XP or Vista. There are no security warnings, etc so I don't think it has to do with that.

And, if my memory serves me correctly, this worked on IE8 a while ago.

What am I doing wrong here? Am I missing something out of the headers?

Is there a way for me to see what header information normal comes over when viewing a PDF in IE8 so I know what to emulate?

After looking at things it still works in IE8 EXCEPT when SSL is on

Jason
  • 15,017
  • 23
  • 85
  • 116

6 Answers6

18

Under HTTPS and IE8, those headers fix the download problem:

header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Pragma: public");

Other X-something headers did not make any difference.

mikikg
  • 1,488
  • 1
  • 11
  • 23
  • This is what worked for me. Also, having 'no-cache' anywhere in your Cache-Control header causes the download to fail in IE8. I've read elsewhere this is because IE8 "caches" your download in its temp folder while transferring, but can't verify this. – jamesvl Feb 21 '13 at 23:58
  • this is one of those the times when one thanks stackoverflow to exist, and @mikikg in that precise case. I looked for this header fix for weeks. – Peter Host Jul 17 '13 at 15:14
  • Best answer indeed. To deliver the PDF I used `header('Cache-Control: max-age=2592000, public, post-check=0, pre-check=0');` without the `must-revalidate` and it works as well. – Avatar Oct 08 '13 at 19:39
  • I had this issue with HTTP and this fix worked for me too. Thanks! – alex23 Jul 15 '14 at 17:15
  • For those who read this and want to use post and pre-check, they may want to look at the following article: http://blogs.msdn.com/b/ieinternals/archive/2009/07/20/using-post_2d00_check-and-pre_2d00_check-cache-directives.aspx – Paddy Sep 17 '14 at 10:20
2

It has probably to do do with the SSL. I read this article (in German, with code examples) where the author set the following header:

header('Pragma: anytextexeptno-cache', true);
chiborg
  • 26,978
  • 14
  • 97
  • 115
1

I'm not sure what is needed, but here is what you could do. Put the file temporarily in a public place on your server, make syre you can download that with a direct link in IE8, Use firefox LiveHTTP headers or similar to grab all headers that the server sends. Spit them out in exactly the same way and order in your script. (And don't forget to delete the file).

user152247
  • 36
  • 3
  • 1
    I was going to say exactly the same thing. Fiddler will also give you the headers with IE. – russau Aug 07 '09 at 05:08
  • Thanks, that did the trick. I found out I was sending the wrong set of headers to IE (I was using the set I send to firefox) – Jason Aug 07 '09 at 14:02
1

Something I want to add, as I faced this problem, too, in a slightly different way using Joomla.

Normal PDF-Output of content worked fine, in all browsers.

But the generation of a pdf from within my own component (using JDocument, tho) generated the bevahiour mentioned above.

My solution: Explicitly enable caching for my component using the following statement in view.html.php:

JResponse::allowCache(true); 

Maybe that helps somebody.

Fabian
  • 11
  • 1
0

I'm using HTTPS and i had some problems, but using those headers the download did. Try it.

header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Pragma: public"); 
header("X-Download-Options: noopen "); // For IE8
header("X-Content-Type-Options: nosniff"); // For IE8
header("Content-type: application/pdf");
header("Content-disposition: inline; filename=file.pdf");
header("Content-length: 7735");

The problem is you cant direct open. Just save.

0

Possibly related: Can't display PDF from HTTPS in IE 8 (on 64-bit Vista)

Community
  • 1
  • 1
Deanna Gelbart
  • 387
  • 2
  • 11