Forum Moderators: coopster
$filePath = the_path_to_a_file;
$file = fopen($filePath,"rb");
// send custom 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
//update the request count in the db
code to update the database goes here
if you get a bunch of users downloading at the same time your cpu usage will eventually get used up. Personally, I wouldn't record the completed download, just that it was initiated and then send them the file. Thatw ould allow the download but not keep the script itself running.
Any reason why you specifically need to track completed?