| « Kidneys - Dad & Ed are doing OK | Maynard's goes YouTube (You cannot be serious!) » |
Corrupted ZIP file downloads with PHP
Wow, what an exciting topic! Move on quickly to the next one, unless you're interested!
Here's the problem: You've got a PHP download script on your site, and your customers are downloading ZIP files, but when they try to open the file, it says its corrupt!
You can't work it out, because the files are fine when you upload them, and the customer is actually downloading a file. You've tried every combination of "header.." in your PHP, and still it's rubbish...
I had this problem when I tried to get OsCommerce to include a Content-Length header so that the user would know how long the download would take.
The reason the problem occurred was because OsCommerce had gzip compression on, and for some reason when you combine this with a Content-Length header, it truncates the file.
Eg: a test.zip file of actual size 5388599 bytes would be downloaded as a file of 5388599 bytes if I didn't have a
header('Content-Length: '.filesize(etc...));
statement, or as a file of 5387710 bytes when I did! Both times the Content-Length header reported 5388599 bytes, the correct size.
The answer: get rid of the Content-Length header, or turn off gzip compression. In OsCommerce this is done in the admin / configuration / gzip compression panel. I've hard-coded it into the PHP so that I can have gzip for the rest of the site, and just not for downloads.
Hopefully MGBT's downloads will work again now...![]()
Trackback address for this post
1 comment
Your blogpost should fill the blank space in google search which was previously absolutely useless for me. And now, when I suddenly changed search keywords to something very impossible, I've found your blog... a miracle, you've solved my and my users problem, thanks a lot again! ;)