NYCPHP Meetup

NYPHP.org

[nycphp-talk] Force File Download HTTP Headers and IE Issue

Jeff Knight jeffknight at mac.com
Wed Sep 3 17:36:07 EDT 2003


 From the reader comments at php.net/manual
http://www.php.net/manual/en/function.header.php
(I'm not being a RTFM smartass, I just happened to be there very 
recently)

simon dot lee at terago dot ca
    28-May-2002 05:50
  Additional notes to my workaround on Q266305:

  I have tested my findings with PDF, XLS, DOC and ZIP. However JPG and 
GIF didn't make IE pop up the download box.  By changing content type 
from "octet-stream" to "force-download" (or some undefined type), it 
will work. Of course, we need to take care of other browsers too. Here 
is the improved code, hope it helps:

  header("Content-type: application/force-download");

  if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE"))
    header("Content-Disposition: filename=$myfile" . "%20"); // For IE
  else
    header("Content-Disposition: attachment; filename=$myfile");     // 
For Other browsers

  Note: If you are using session together with this download, you will 
need to add the following line BEFORE the code above to make IE work:

  session_cache_limiter("");



======


It (or some other voodoo) got my thing working.... good luck.

Of course, while you're there you'll also find an endless discussion of 
."%20", other IE 6, 5, 4, 3, 2, 1 and Opera on my Highly Customized 
Toilet discussions....

On Wednesday, September 3, 2003, at 04:21  PM, pswebcode, nyc wrote:

> My question:
> Anyone got a working runaround suggestion to force file downloads on 
> IE?
>
> My issue(s):
> I am using PHP to write HTTP headers to force pdf file download to user
> roughly as follows:
>
> blah, authenticate user, blah, select $file, blah... then push with...
>
> header ("Content-Type: application/octet-stream");
> header("Content-Transfer-Encoding: Binary");
> header("Content-Length: $iFileSize");
> header ("Content-Disposition: attachment; filename=$iFileName");
> readfile("$file");
>
> Netscape conforms and opens the Save As... dialog as expected. IE6 
> messes up
> the content-disposition header and opens the download inline in the 
> browser
> without prompting user to Save As...
>
> Seems regardless, of content-type header specified:
> application/octet-stream
> application/force-download
> application/pdf
>
> IE will mess it up. This is a known issue. Best run around I've seen 
> so far
> is to .Zip the files, in which case IE offers the Save As... on the
> download. Don't want to zip em.
>
> Thoughts?
>
> Warmest regards,
>
> Peter Sawczynec, Technology Director
> PSWebcode -- Web Development and
> Site Architecture
> psaw at pswebcode.com
> www.pswebcode.com
> 718.543.3240
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
>

Jeff Knight
jeff at lushmedia.com
212/213-6558 x 203
LUSH media
110 W 40th St #1502
New York, NY 10018



More information about the talk mailing list