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

i Think its cool.

Just @ the header
@header.

IE will try to mess-up without it on xp sp1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.