Zip files corrupted on download in internet explorer no FF or Chrome
Aghh the joys of working with websites..
One step forward another step back.
Scenario
You have zipped files available for download from your site, blog, CMS etc. When you test the download process our in IE you get an error:
The Compressed (zipped) Folder is invalid or corrupted.

However, when you test the download with Firefox or Chrome all works fine. You may even be able to open the file via 7zip or Winrar. However, normal people (non-geeks) will not be able to enjoy your amazing zipped files. This can be especially irritating if you are trying to sell downloadable files via Magento or similar. The problem is probably related to the way in which you have told apache to gzip your site. Check to make sure that you (or your software package) have not applied the following in either .htaccess or httpd.conf
SetOutputFilter DEFLATE
This essentially tells apache to compress all files being sent to the browser. Fine unless you have already compressed a file. This double compression clearly damages the files in transit leading to the problem above. I have yet to figure out why FF or chrome seem to compensate for this. Either way you need to be more specific in how you tell apache to compress what.
Something like this should be used
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
#AddOutputFilterByType DEFLATE application/x-httpd-phpBrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/htmlSetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:pdf|doc)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp3|mp4|rm)$ no-gzip dont-vary
The top block explicitly tell the server what type of files to compress. The middle block targets the browsers. The final block will exclude php generated media formats which again do not need to compressed twice.
Related Posts
| Print article | This entry was posted by Andy Bird on July 20, 2010 at 10:39 pm, and is filed under apache, linux. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
This was the solution I found to the zip file issue:
EDIT – .htaccess file
The problem with compressed downloadable products is caused by headers sent by server if you enable zlib compression and apache OutputFilter DEFLATE on all content in .htaccess file.
The solution is to disable those filters. Search for these two sections/lines of code and comment them or uncomment them (i.e. put # in front of them) so they look exactly like the code below:
# php_flag zlib.output_compression on
…
…
…
# Insert filter on all content
### SetOutputFilter DEFLATE # problems with downloadable content
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
# Netscape 4.x has some problems…
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don’t compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary