0

On a site I'm working on we need to allow a user to download a file once only. The problem is, if the download fails they can try again. I only want it to be registered as a download if it completes successfully
The code I'm using at the moment;

set_time_limit(0);
ignore_user_abort(false);

//----------
//Code to validate the download token, make sure it hasn't been downloaded before etc.
//----------

//Send the headers
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$RemoteName.'"');
header('Content-length: '.filesize($LocalName));

//Send the file
ob_start();
$f = fopen($LocalName, 'r');
while(!feof($f)){
    echo fread($f, 1024*1024*5);
    ob_flush();
}
fclose($f);

//Update the database
mysql_query("UPDATE TABLE SET FIELD = 'DONE' WHERE ID = '$DLID'");

This seems to be working fine (The mysql_query doesn't run if the user aborts/cancels/fails) but will there be any issues with browser compatibility or a better way to do it?
-Sam

Edited by samarudge: Remove table/field names from SQL code

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by richieking
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.