How large is the corrupted file compared to the others? Are you actually sending the correct size? What do you headers look like on the download script? They should look similar to this:
PHP Code:
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: $mtype");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"".basename($file)."\"");
if (ini_get('allow_url_fopen')) {
if (extension_loaded('curl')) {
header("Content-Length: " . remotefsize($file));
}
}
header("Accept-Ranges: bytes");
Next, why did you write your own function to "chunk" the data? You can use something as simple as:
PHP Code:
@readfile("$filename");
If all you ever intend on sending the user is zip/compressed files you can simply forward their browser to the file URL. IE:
PHP Code:
header("Location: " .$file);
There is no reason to force a download for these type of files as the browser will do that anyway.
Here is some things you can do:
1) Download the file. Once complete open it with a text-editor and see if any text data is getting added to the beginning or ending of the file that shouldn't be there.
2) Does the file download when you link directly? If not, then it isn't your PHP script. You've corrupted the file somehow.
3) Try to use the php readfile function above and see if it is just your chunk function.
4) Make sure your headers are correct.
I hope this helps. You can download the community project "ionFiles" here on CodeCall. If you look at the download.php file you can see how our PHP file download script works.