HTTP headers!

Soldato
Joined
26 Dec 2003
Posts
16,522
Location
London
Can someone well versed in the intricacies of murky HTTP magic tell me why the heck this produces corrupt downloads for some people?

Code:
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Length: '.filesize($filename));
readfile($filename);

$filename is and always will be a zip file, so I don't need to mess about with dynamically working out the mime-type. As far as I and Google know, application/zip is universally understood, so it can't be that. From examining the headers sent, the content-length is accurate, and the filename is being set in the content-disposition line.

The trickiest part is that I am totally unable to reproduce the errors myself; Firefox, IE, Opera and humble wget all download the zip fine and it's totally intact/well-formed. I'm totally pulling my hair out :(

I'd appreciate some help debugging, so if you don't mind downloading this zip file and - provided you get a corrupt file - posting your browser/OS/zip utility, I'd really appreciate it. Otherwise I'll just presume no news is good news and ignore it :)
 
:confused: strange , it might be the other users browser setup because i used to always get corrupt drivers from ATI.com till i formatted! - No one else I knew did :confused:
 
I found this which seems confirmed on php.net/header - seems that some versions of IE like to ignore Content-Disposition.

Apparently, IE also needs 'Pragma: public' for some quirky reason.

Lastly, 'Content-Transfer-Encoding: binary' may be useful but I shouldn't think it's necessary...seems to work alright on whatever I download, and I've never seen it before this research :)
 
Tried adding those. It's the weirdest bug I've ever come across though; one user said this:

"I am presently in LA; here is where I downloaded a corrupt file. When I remotely connected to a computer in Chicago a few minutes ago, I downloaded the file uncorrupted. Interesting."

:(
 
Have you got a checksum of the original file we can compare against? If the checksum matches for people, but the zip is still considered corrupt, then you I guess you can rule out transmission errors and put it down to the zipping software. I've seen occasions where regular .zip files will open with a program like 7zip, but not others - which may be down to tolerance of errors/error correction ability.

Server not responding for me at current; will try later :).
 
Back
Top Bottom