Forum Moderators: coopster

Message Too Old, No Replies

Download counter - only if file was fully downloaded

         

royp2000

1:51 pm on May 14, 2007 (gmt 0)

10+ Year Member



Hi,

I'm looking for a script that will count how many tiles a file was downloaded from my site, But only if the file was fully downloaded.

Is there a way to do that automatically?

Thanks,

Roy.

joelgreen

3:10 pm on May 14, 2007 (gmt 0)

10+ Year Member



Looks like some download script needs to be developed, which would send a file via socket and check status code. If socket is closed before whole file is sent - do not count as complete download. But i have no experience in this area.
So I am also interested in answer to this question.

jezra

7:19 pm on May 14, 2007 (gmt 0)

10+ Year Member



I have a download script that I send a filename to based on a user request. Upon completion of the download, a database table is updated to reflect the download.

$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

joelgreen

12:14 pm on May 15, 2007 (gmt 0)

10+ Year Member



Thank you for example jezra :)