Forum Moderators: coopster

Message Too Old, No Replies

download track - justageek

continuation of old post

         

Shawazi

8:29 am on Mar 17, 2004 (gmt 0)

10+ Year Member



Hey I saw this post:
[webmasterworld.com...]
on the site but I still have a question. It says

"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?

justageek

12:08 pm on Mar 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is a little piece that will send a file.

$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