By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,825 Members | 1,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,825 IT Pros & Developers. It's quick & easy.

Serving ZIP files to IE using PHP

P: n/a
Hi,
I've been wrestling for several months now with this issue in IE:
http://support.microsoft.com/?kbid=308090

(IE thinks that ZIPs sent from a script are corrupt when they are not).
IE now also seems to think that many other files are ActiveX controls
and pops up the "Some files may damage your computer...Open Save
Cancel" dialog.

However, I am quite certain that others have managed to use a script
serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
do just that a moment ago.

I am currently using IIS and a Windows-ized version of mod_rewrite to do
URL rewriting so that IE in theory should not know that it is receiving
a ZIP file from script. Nonetheless, the error occurs even with
rewriting invoked. The problem seems to be that after IE pops up its
security dialog, it does not issue another HTTP request, but seems to
expect to go get the file.

Can anyone give me advice on how to do this? A tutorial, a newsgroup
thread, anything would be useful...

Thanks,

Eric
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Wed, 31 Mar 2004 12:12:08 -0500, Eric Ellsworth wrote:
However, I am quite certain that others have managed to use a script
serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
do just that a moment ago.

Eric..

I coded this function a long time ago that works without issue with ZIP
files (just tried it with IE6 too):
function download($file) {
if (empty($file) || !@file_exists($file)) return false;

@header('Content-type: archive/tar');
@header('Content-length: ' . @filesize($file));
@header('Content-disposition: attachment; filename=' .
array_pop(split('/', $file)));
@header('Content-transfer-encoding: binary'); @readfile($file);

return true;
}
$file in this case is a complete path name hence the array_pop() and
split() calls to retrieve just the filename to send as the file to be
saved.

Hope this is at least of some help to you =)

Regards,

Ian
[XP trimmed (php.lang not available on my news server)]

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2

P: n/a
On 03/31/2004 02:12 PM, Eric Ellsworth wrote:
I've been wrestling for several months now with this issue in IE:
http://support.microsoft.com/?kbid=308090

(IE thinks that ZIPs sent from a script are corrupt when they are not).
IE now also seems to think that many other files are ActiveX controls
and pops up the "Some files may damage your computer...Open Save Cancel"
dialog.

However, I am quite certain that others have managed to use a script
serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
do just that a moment ago.

I am currently using IIS and a Windows-ized version of mod_rewrite to do
URL rewriting so that IE in theory should not know that it is receiving
a ZIP file from script. Nonetheless, the error occurs even with
rewriting invoked. The problem seems to be that after IE pops up its
security dialog, it does not issue another HTTP request, but seems to
expect to go get the file.

Can anyone give me advice on how to do this? A tutorial, a newsgroup
thread, anything would be useful...


There is nothing that can be done except for telling the user to save
the file and open it later.

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #3

P: n/a
Hi Ian,
Thanks for the quick reply - I will try using your code. Do you mind
if I ask why you used the @'s in front of the header function?

Thanks,

Eric

Ian.H wrote:
On Wed, 31 Mar 2004 12:12:08 -0500, Eric Ellsworth wrote:

However, I am quite certain that others have managed to use a script
serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
do just that a moment ago.


Eric..

I coded this function a long time ago that works without issue with ZIP
files (just tried it with IE6 too):
function download($file) {
if (empty($file) || !@file_exists($file)) return false;

@header('Content-type: archive/tar');
@header('Content-length: ' . @filesize($file));
@header('Content-disposition: attachment; filename=' .
array_pop(split('/', $file)));
@header('Content-transfer-encoding: binary'); @readfile($file);

return true;
}
$file in this case is a complete path name hence the array_pop() and
split() calls to retrieve just the filename to send as the file to be
saved.

Hope this is at least of some help to you =)

Regards,

Ian
[XP trimmed (php.lang not available on my news server)]

Jul 17 '05 #4

P: n/a
[ Thread rearranged into chronological order ]
Ian.H wrote:

[ snip ]
function download($file) {
if (empty($file) || !@file_exists($file)) return false;

@header('Content-type: archive/tar');
@header('Content-length: ' . @filesize($file));
@header('Content-disposition: attachment; filename=' .
array_pop(split('/', $file)));
@header('Content-transfer-encoding: binary'); @readfile($file);

return true;
}

[ snip ]
On Mon, 05 Apr 2004 16:22:52 -0400, Eric Ellsworth wrote:
Hi Ian,
Thanks for the quick reply - I will try using your code. Do you mind
if I ask why you used the @'s in front of the header function?

Thanks,

No probs at all.. hope it helps you =)

The @ char before a function in PHP supresses any errors/ warnings that
function may produce.

We're not looking for browser output here and I don't need the error
checking in the function (the way I used/ coded it anyway) as this is done
separately.. so to keep PHP quiet just incase.. I supressed the output.

For the actual checking.. I'd do something like:
<?php
[...]

if (is_readable($file)) {
download($file);
} else {
/* Throw some kind of error about problem reading file... */
}

[...]
?>
or something along those lines. The reason the "validation" was done
outside of the function as it was part of a much larger script and had
other considerations I needed to take into consideration etc =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #5

P: n/a
Eric Ellsworth wrote:
Hi,
I've been wrestling for several months now with this issue in IE:
http://support.microsoft.com/?kbid=308090

(IE thinks that ZIPs sent from a script are corrupt when they are not).
IE now also seems to think that many other files are ActiveX controls
and pops up the "Some files may damage your computer...Open Save
Cancel" dialog.

However, I am quite certain that others have managed to use a script
serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
do just that a moment ago.

I am currently using IIS and a Windows-ized version of mod_rewrite to do
URL rewriting so that IE in theory should not know that it is receiving
a ZIP file from script. Nonetheless, the error occurs even with
rewriting invoked. The problem seems to be that after IE pops up its
security dialog, it does not issue another HTTP request, but seems to
expect to go get the file.

Can anyone give me advice on how to do this? A tutorial, a newsgroup
thread, anything would be useful...

Thanks,

Eric

Exactly what code have you tried?
If this isn't what you did, you could sent a content-type header telling the
browser you are sending a ZIP file, or maybe try the content-type
application/octet-stream
Jul 17 '05 #6

P: n/a
> Do you mind if I ask why you used the @'s in front of the header function?

So that it doesn't "complain" if the headers were already sent (aka
not output php's error text).
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.