Re: IE can't download, FF can: SSL ? Need special headers?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 22, 2009 at 11:04 AM, Dee Ayy <dee.ayy@xxxxxxxxx> wrote:
> The following code has been working for about 6 years.  The only
> change I am aware of is that now it is being served from a server
> requiring SSL to access it.
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=\"$name\"");
> echo $data;
>
> It still works in FF, so I assume the variables are being filled in.
> For example:
> header("Content-type: application/pdf");
> header("Content-length: 75485");
> header("Content-Disposition: attachment; filename=\"test.pdf\"");
>
> In DebugBar HTTP(S) after the GET request which had to be authorized
> by htaccess it reports:
> HTTP/1.1 200 OK
> Date: Fri, 22 May 2009 14:38:18 GMT
> Server: Apache/2.0.50 (Fedora)
> X-Powered-By: PHP/5.1.6
> Set-Cookie: PHPSESSID=743ba4d8e056873c4da52b123df4b1ad; path=/
> Expires: Thu, 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
> Pragma: no-cache
> Content-length: 7359
> Content-Disposition: attachment; filename="test.pdf"
> Connection: close
> Content-Type: application/pdf
>
> Should "HTTP/1.1 200 OK" be "HTTPS/1.1 200 OK"?  If so, how can I get
> that set?  Is there some funky header I need?
>
> Oh, the IE 7 error is:
> Internet Explorer cannot download my_php_file.php?a_name=a_value from
> my.site.com.
>
> Internet Explorer was not able to open this Internet site.  The
> requested site is either unavailable or cannot be
> found.  Please try again later.
>
> FYI: If the user cannot choose a filename to save as, it gets saved as
> "my_php_file.php" which needs to be renamed to extension ".pdf" to be
> viewed in a PDF viewer.
> So if you have any helpful headers to force the filename, I'd
> appreciate that too.  Apparently Content-Disposition: attachment;
> filename="test.pdf" doesn't work (on FF and maybe other browsers).
>
> There is an issue with Internet Explorer 6
> http://support.microsoft.com/?kbid=816037 that seems to relate, but
> this is for IE 7, and I can't verify if it is also failing on IE 6.
> But I found this (which didn't work for me)
> http://www.vistaheads.com/forums/microsoft-public-internetexplorer-general/313324-downloading-ftp-files-ie7.html
>
> Regards.
>

I'm not sure about IE7 specifically, but IE is touchy about
downloading documents - especially PDFs. Here are a few things I keep
in mind that have worked so far:

For all browsers, we send the following headers (which you appear to
be setting):
- Content-Type with the correct MIME type
- Content-Disposition as attachment with the file name. I have found
that the filename should be urlencoded to prevent problems with the
file name not being recognized by the browser.
- Content-Length
- Content-Transfer-Encoding: binary

For MSIE, identified by user-agent* we also add cache control since IE
has a problem handling PDF documents when the headers direct it to not
cache the document:
- Expires: date('r', strtotime('+3 hours'))
- Cache-Control: max-age=60
- Pragma: public

* Yes, I know user-agent isn't very reliable, but generally it won't
hurt other browsers if these headers are added to someone who happens
to be spoofing IE.

This has worked pretty well for us so far, and these are being served
via SSL. (Not that they need to be, since they are just blank forms,
but it prevents warnings since the rest of the site is SSL.)

>From what I can tell, IE has a problem with PDFs that are not cached.
It seems that to handle the documents, it saves a copy in the temp
folder and then directs Adobe to open that file when it spawns the
reader. When you tell IE not to cache the document, it dutifully
obliges, but it still tells Adobe to open the file from the temp
folder. At least, that's what it looks like it tries to do.


To get around the filename problems, you could also use some sort of
mod_rewrite where the URL requested is the actual PDF name but let PHP
handle the request if the above doesn't work for you.

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux