File download probs...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

File download probs...

Post by Joe »

I am working on a shopping cart at the moment and I am wondering if it is possible to determine whether a file has been downloaded so I can update the database. It is fairly difficult to explain but look at the code below:

Code: Select all

header('Content-Description: File Transfer');
		header('Content-Type: application/force-download');
		header('Content-Length: ' . filesize($file));
		header('Content-Disposition: attachment; filename=' . basename($file));
		readfile($file);

		$sql_query_mark_download = "UPDATE `videofiles` SET `downloaded`='1' WHERE `id` = '" . $_REQUEST['did'] . "'";
		mysql_query($sql_query_mark_download) or die(mysql_error());
It works well yes, however if the user presses cancel instead of download when the "download file" dialog pops up the query still runs?. Is it possible to make it so if they do press cancel, then the query will not run?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

connection_aborted() may be of interest.
Post Reply