File download is corrupted
Posted: Thu May 01, 2008 4:16 pm
Hey all,
I have a site that sells mp3's. The mp3 files are grouped; so the download is a zip file of about 70-100 MB. The zip files are in .htaccess protected directory of my webserver. The code i use to send the file to the client browser is the following:
Now, everything works fine with all my zip files, except one. There is one zip file that always gets corrupted when you download it. I have recreated the zip file many times, with many different compressors. I have made sure that the file is fine when you upload it through ftp. Yet the file continues to become corrupt on download. Oddly enough, if place outside of the .htaccess protected directory, the download is fine. This does not make sense as all the other zip files get downloaded just fine.
so, the possible sources of the problem are:
* the file is in an .htacces protected directory -- yet all other files download fine
* the zip file is corrupted on ftp upload -- yet, if placed in another location within the server, the download is fine
* the zip file is created with a lousy compressor -- windows, mac and linux compressors have been tried
* the code to send the file is buggy -- yet all other files download fine
Any insight on the true source of the problem and how it might be solved is greatly appreciated.
Cheers
I have a site that sells mp3's. The mp3 files are grouped; so the download is a zip file of about 70-100 MB. The zip files are in .htaccess protected directory of my webserver. The code i use to send the file to the client browser is the following:
Code: Select all
function vmReadFileChunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
sleep(1);
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}so, the possible sources of the problem are:
* the file is in an .htacces protected directory -- yet all other files download fine
* the zip file is corrupted on ftp upload -- yet, if placed in another location within the server, the download is fine
* the zip file is created with a lousy compressor -- windows, mac and linux compressors have been tried
* the code to send the file is buggy -- yet all other files download fine
Any insight on the true source of the problem and how it might be solved is greatly appreciated.
Cheers