Results 1 to 2 of 2
Jul 12, 2009, 09:07 #1
insert into the database after downloading an file
I am providing the users to download a file. I wants to have user log for downloading the file.
I want that if an user really download the file then it should enter in the database. Below is the code i am using.
$file = strip_tags($_GET['q']);
// Quick check to verify that the file exists
if( !file_exists($file) ) die("File not found");
// Force the download
header("Content-Disposition: attachment; filename=\"" . basename($file) . "\"");
header("Content-Length: " . filesize($file));
//INSERT INTO DATABASE
Currently when someone clicks on the file it saves in the database instantly insead of actual download.
Jul 12, 2009, 15:49 #2
- Join Date
- Jul 2008
- 0 Post(s)
- 0 Thread(s)
There's no solid way to know if they really downloaded it. Some(all?) browsers start downloading before you even make the choice of whether or not to cancel.
All you can really do is measure how many bytes your script outputs, and compare that to the filesize. Depending on the webserver, and how you have php interface with it, this will probably only tell you how many bytes you gave to the webserver. It doesn't tell you how many bytes the webserver gave to the client, nor how many bytes the client received.
If you still want to proceed to do this, make sure you turn output buffering off. Then you can output a little at a time with fread(), while using flush() and checking the connection http://www.php.net/manual/en/feature...n-handling.php