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.

PHP Code:
// 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));
header("Content-Type: application/octet-stream;");
When an user clicks on an file name , it prompts an download window with as usual two options download and cancel. What i would like to have is that when someone really downloads the file then it should insert in the database.

Currently when someone clicks on the file it saves in the database instantly insead of actual download.

Please help.