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