Re: php downloads with IE and Netscape not working
From: Dang Nguyen (dang155_at_comcast.net)
Date: 10/03/03
- Next message: Dang Nguyen: "Re: if..else condition for checkbox"
- Previous message: Raditha Dissanayake: "Re: [PHP] PHP & EJB"
- In reply to: Dang Nguyen: "php downloads with IE and Netscape not working"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
>
>
>
>
- Next message: Dang Nguyen: "Re: if..else condition for checkbox"
- Previous message: Raditha Dissanayake: "Re: [PHP] PHP & EJB"
- In reply to: Dang Nguyen: "php downloads with IE and Netscape not working"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|