Incomplete Downloads with Wordpress Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
citizen_insane
Forum Newbie
Posts: 1
Joined: Thu Jul 14, 2011 8:29 am

Incomplete Downloads with Wordpress Script

Post by citizen_insane »

I've been using a modified version of the Wodpress Download Codes plugin for a record label website that I've created that allows people to download digital albums. The zip files are about 130mb +-20mb. The issue we're having is with some users reporting issues of incomplete downloads. The download will finish (doesn't stop in the middle) but it will be a different size than the file hosted on the server. This leads me to believe that the file is only partially downloading thus corrupting the zip file.

The issue has been reported on all operating systems and browsers, but I have never witnessed it myself, just gotten the feedback from users/testers. Here is the code used to stream the file, can anyone see a reason why I would be having issues?

Code: Select all

// Stream file
	$handle = fopen( dc_file_location() . $release->filename, 'rb' );
	$chunksize = 1*(1024*1024);
	$buffer = '';
	$cnt =0;
 		if ($handle === false) {
			return false;
		}
		while (!feof($handle)) {
			$buffer = fread($handle, $chunksize);
			echo $buffer;
			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;
Post Reply