PHP If user download file fully?

User begins to get a file :
1) can get as by one stream so by the unlimited amount of streams
2) User can continue download the file and script gives him a file by bytes ( or kb ), well and able to give pieces ( for streams ) !  

it is needed to define is a file got fully ONCE ? after download it to forbid getting of this file another time....

My algorithm: to add up the given amount of information for user from all of streams and write to DB ! In the end to check with files this sum ... well and to draw a conclusion to forbid or not ! Here are a few nuances, how to know user pressed STOP ? Maybe did user come to renew download ? Or anew to rock a file ?
Who is Participating?
Here is some information i found on this matter, i persoanally do not know how you do it but i hope this can help in some way

$filename = "the name of my file";
$filePath = "/path/to/download/$filename";
//lets read this file to the user
//open the file for binary reading
$file = fopen($filePath,"rb");
// we build some headers
header("Content-type: application/octet-stream");
header("Content-Disposition: inline; filename=\"$filename\"");
header("Content-length: ".(string)(filesize($filePath)));
while(!feof($file) )// if we haven't got to the End Of file
print(fread($file, 1024*8) );//read 8k from the file and send to the user
flush();//force the previous line to send its info
if (connection_status()!=0)//check the connection, if it has ended...
fclose($file);//close the file
die();//kill the script
fclose($file);//close the file
//if we get this far, the file was completely downloaded
//update the database
noviceexpertAuthor Commented:
This script will download only in 1 thread and watch if the full file send to user! I want create a script wich can watch the full send to user with unlimited threads and user can continue download if it crashed.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.