Forum Moderators: coopster
"I then chunk the file to them which I use to see how much of the file has been sent. This way I know if a user has the entire file or what percentage of the file was sent."
"For the aborted downloads use the connection_status() so you can clean up any orphan records"
-justageek
What do you mean by chunk the file and how does connection_status work?
$path = "Wherever_you_keep_your_files";
$name = "Whatever_file_you_want_to_send";
$myfile = $path.$name;
$myfilesize = filesize($myfile);
//If the download is stopped by the user the script will continue.
ignore_user_abort(true);
//Open the file and send it as long as there was not a user abort and the file exists.
if ($file = fopen($path, 'rb')) {
$x = 1;
$sStart = microtime();
while(!feof($file) and (connection_status()==0)) {
print(fread($file, 1024));
flush();
$percent = ((($x * 1024) / $filesize)*100);
$x++;
}
}
fclose($file);
//Either the script finished or there was a user abort so add the stats to a db
$sEnd = microtime();
$aA = explode(' ',$sStart.' '.$sEnd);
$deliverytime=sprintf('%03.8f Seconds',($aA[2]+$aA[3])-($aA[0]+$aA[1]));
addstats($name,$filesize,$percent,$deliverytime);
The addstats function just adds the information I need so change it to whatever you need. The percentage will not be exact because it is set to 1k chunks which works fine for me but might not for you so change it if need be.
JAG