Hi, I'm a relatively experienced PHP programmer, but I was wondering if there was a way to execute a block of code only if a file was downloaded successfully (that is, only if the user downloaded the file COMPLETELY, not just clicked on the link and cancelled).
Here's a basic layout of what I'm doing. I know for a fact that this code works fine. I just need to know what I could do to create a condition to put into "DOWNLOAD WAS SUCCESSFUL". Is there any way that PHP can actually track this, or is it something that is completely client-side? Thanks for any help you can give.
//if this request is an actual file, send it out and forget everything prior to it
if (!is_dir(stripslashes($url))) {
//send the file
header("Content-Type: application/octet-stream");
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header ("Content-Length: " . filesize(stripslashes($url)));
header("Content-Disposition: attachment; filename=\"" . stripslashes($dir) . "\"");
header("Content-transfer-encoding: binary");
readfile(stripslashes($url));
if (DOWNLOAD WAS SUCCESSFUL) {
//log the bandwidth
$link = @mysql_connect('localhost', $MySQL['username'], $MySQL['password']);
mysql_select_db($MySQL['database'], $link);
$userInfo = mysql_fetch_array(mysql_query("SELECT bandwidth FROM member WHERE name = '$username'", $link));
$bandwidth = $userInfo['bandwidth'];
$bandwidth += filesize(stripslashes($url));
mysql_query("UPDATE member SET bandwidth = '$bandwidth' WHERE name = '$username'", $link);
mysql_close($link);
return;
}
}