Hi, I'm using fread and header to deliver files to my visitors. It works fine with jpg, mp3 etc, but zip and exe always end up being corrupted. I checked their filesize, and the delivered zip/exe is always 1byte larger than the original file. Here's a sniplet my code:

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header('Content-Description: File Transfer');
header("Content-Type: $mime");
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);


Anyone can advise? Thanks.

    1. Double check that there is no whitespace outside of the <?php ?> tags. If you're not sure, attach the entire .php script (as a .txt file) to your post so we can see.

    2. Try using application/octet-stream as your Content-Type.

    3. Provide a URL to this script in action for us.

      One clue might be the nature of the extraneous byte. Is it at the beginning or the end of the corrupted zip file (it should start PK\003\004)? What byte is it, exactly?

        Write a Reply...