Re: php downloads with IE and Netscape not working

From: Dang Nguyen (dang155_at_comcast.net)
Date: 10/03/03


Date: Fri, 3 Oct 2003 04:50:04 -0700

Sorry, some misinformation in my post. I stated that these were pdf files,
but the code shows that I am sending zip files. I should have stated that I
was sending zip files to the user's browser, not pdfs. In any case, the
code doesn't work as is. Users get a "invalid zip archive" error when they
choose to "Open" the zip file and even if they first save it to their local
drive. However, the temp file that IE creates when it first downloads the
file is a valid zip file. So somewhere between creating the temp file and
then moving the file to its final location or opening it, IE screws up the
zip archive.

Here's how I worked around this IE bug:

(Works in Netscape, but does not work in IE)
header("Content-Type=application/x-zip-compressed");

(Works in IE and Netscape)
header("Content-Type=application/download");

Basically, IE does not handle the mime-type as a zip file correctly when I
specify that its a zip file. I have to make up a bogus mime-type (i.e.,
"application/download").

My final code snippet looks like this:

// workaround due to IE mime-type bug
if($type == "application/x-zip-compressed" &&
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') > 0) { // detect zip file and
user's IE
          header("Content-Disposition: attachment; filename=".
basename($file));
          header("Content-Transfer-Encoding: binary");
          header("Content-Type: application/download");
}
else if($type == "application/x-zip-compressed") { // use this for zip
files when the user's browser is not IE
           header("Content-type: $type");
           header("Content-Disposition: attachment; filename=".
basename($file));
           header("Content-Transfer-Encoding: binary");
}
else { // all other types of files, regardless of browser
           header("Content-type: $type");
           header("Content-Disposition: filename=". basename($file));
}

"Dang Nguyen" <dang155@comcast.net> wrote in message
news:o_OdnUuwbMMWHuaiRVn-iw@comcast.com...
> Hi All,
>
> I have a php script that users in our intranet use to download files from
> the web server. The script works some of the time in Netscape 7.1, but it
> doesn't work at all in IE. The files being requested are all pdf files.
> Thanks for any assistance resolving this problem.
>
> This is the code:
>
> @clearstatcache();
>
> if($fp = fopen($zip_parent.$my_zip, 'rb')) {
> // send the new zip file containing the subset of files back to
the
> client's browser
> header("Cache-control: private");
> header("Content-Type: application/x-zip-compressed");
> header("Content-Disposition: inline; filename=\"". trim($my_zip).
> "\"");
> header("Content-Description: ".trim($my_zip));
> //header("Content-Length:
> ".(string)(filesize($zip_parent.$my_zip)));
> header("Connection: close");
> error_log("download.php: ". filesize($zip_parent.$my_zip));
>
> // dump the file
> fpassthru($fp)
> or die("fpassthru had an error: ". mysql_error());
> fclose($fp);
>
> // clean up the filesystem when we're done
> if($_SERVER['REQUEST_METHOD'] == "POST") {
> unlink($zip_parent.$my_zip);
> }
> }
> else {
> header("HTTP/1.0 404 Not Found");
> }
>
> Dang Nguyen
>
>
>
>



Relevant Pages

  • Re: pdf files and Internet explorer (created on Mandrake)
    ... but it's a fundamental danger to the security and stability of their ... > and served by Apache. ... all my .pdf files start with %pdf. ... who now need a browser check on their website's index page to prevent IE ...
    (alt.os.linux)
  • Re: Hyperlinks open as Read-only??
    ... I opened a local pdf file and then changed this setting in Reader: ... uncheck "Display PDF in Browser" ... Also don't install toolbars to open PDF files in ...
    (microsoft.public.excel)
  • Re: Internet Explorer issues
    ... Try this and apply to .pdf files as well. ... If it is only .exe files, then read on and see if this is relevant: ... Blank Web Page with Placeholder Icon and You Cannot Save a File to ... For some reason my browser ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: How to force download?
    ... The "attachment" specification requests the browser to download the file ... "Miguel Dias Moura" wrote in message ... > in my web site i display some links to PDF files. ...
    (microsoft.public.dotnet.framework.aspnet)
  • adobe and netscape 7
    ... I am trying out netscape 7 on my solaris 9 workstation and I cannot seem ... system and it has no problems opening pdf files as a helper application. ...
    (SunManagers)