complete downloads
Posted: Sun Feb 19, 2006 5:43 pm
hi
i am looking for a method to update a counter everytime a download has been completed. at the moment the counter updates if the download has a/ completed b/ timedout or c/ cancelled (even if its hit & cancelled)
at the moment the code is the following:
any help would be most appreciated
i am looking for a method to update a counter everytime a download has been completed. at the moment the counter updates if the download has a/ completed b/ timedout or c/ cancelled (even if its hit & cancelled)
at the moment the code is the following:
Code: Select all
// Now send the file with header() magic
header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: Application/octet-stream");
header("Content-disposition: attachment; filename=" . $downloads->fields['orders_products_filename']);
$zv_filesize = filesize(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']);
//@ignore_user_abort(true); // when not commented out the counter never updates
if (DOWNLOAD_BY_REDIRECT == 'true') {
// This will work only on Unix/Linux hosts
zen_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC);
$tempdir = zen_random_name();
umask(0000);
mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777);
symlink(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename'], DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads->fields['orders_products_filename']);
if ((connection_status()==0) and !connection_aborted() ) {
//update counter
$db->Execute("update " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " set download_count = download_count-1 where orders_products_download_id = '" . (int)$_GET['id'] . "'");
} else {
//download aborted
}
zen_redirect(DIR_WS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads->fields['orders_products_filename']);
} else {
// This will work on all systems, but will need considerable resources
// We could also loop with fread($fp, 4096) to save memory
header("Content-Length: " . $zv_filesize);
readfile(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']);
}