jaguar080 Posted May 2, 2008 Share Posted May 2, 2008 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: 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; } 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 Quote Link to comment Share on other sites More sharing options...
SharkBait Posted May 2, 2008 Share Posted May 2, 2008 How is it being corrupt? The way I found out if something was an issue with a download I would open up the corrupt file via notepad or something. What I found when my downloads were corrupt was that the header of the file was including an error message. In my case it was because the actual filesize was different than the filesize I was passing to the header function when I would initiate the code to prompt the user to save the file to a location. Quote Link to comment Share on other sites More sharing options...
jaguar080 Posted May 4, 2008 Author Share Posted May 4, 2008 I just checked if there is an error message appended to the downloaded file, there is none. the file sizes are slightly different though, the downloaded file is smaller. this is the bit where i set the file size in the headers, how can this go wrong? header('Content-Length: ' . filesize($filenameandpath) ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.