views:

732

answers:

3

I am delivering a ZIP file in 64k chunks using a loop in PHP (but the problem would arise with any server side language).

When fetching the file with FF, everything goes just fine.

When fetching the file with IE7, some bits get corrupted. This leads to an error message regarding wrong CRC (a hash) and some of the unzipped files end up being corrupted.

The headers being sent are the following:

Expires: 0
Cache-Control: must-revalidate, post-check=0, pre-check=0
Pragma: public
Content-Description: File Transfer
Content-Disposition: attachment; filename="671fb8f80f5e94984c59e61c3c91bb70.zip";
Content-Transfer-Encoding: binary
Vary: Accept-Encoding
Content-Encoding: gzip
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/octet-stream

Does anyone have a clue where this corruption comes from?

+3  A: 
Content-Encoding: gzip

Did you intend to gzip your (already compressed) zip? I assume your web server adds this header, but if you added it yourself with PHP then maybe this could be the problem?

finalman
i did not add this header by myself. this is a header set by apache.
Pierre Spring
+1  A: 

This MSDN article explains that IIS encodes ZIP files using gzip, but without the proper headers, it won't decode it before sending it to the unzipping program. Firefox is probably smart enough to automatically decode it. A fix is mentioned in the article, thought the article title doesn't exactly mention your issue.

I would double-check your IIS settings just in case.

Cory Larson
sorry for not mentioning the fact that we work on a lamp stack ;) the zip file is generated by php and then sent out by php itself.
Pierre Spring
I should have deduced that... I've been stuck in the .NET world for so long that I like to immediately blame IIS :)
Cory Larson
+5  A: 

Thanks to the previous answers, i managed to solve the problem:

Apache's mod_deflate encoded the responses in gzip. This had two effects when sending the file in chunks:

  1. The Content-Length header was not sent out
  2. The delivered files were corrupted when using IE7

The solution, in php, is to disable the encoding of the response using the following command:

apache_setenv('no-gzip', '1');
Pierre Spring