Execute($sql); if (!$downloads_result->RecordCount()) die; $downloads = $downloads_result->fields; // MySQL 3.22 does not have INTERVAL list($dt_year, $dt_month, $dt_day) = explode('-', $downloads['date_purchased_day']); $download_timestamp = mktime(23, 59, 59, $dt_month, $dt_day + $downloads['download_maxdays'], $dt_year); // Die if time expired (maxdays = 0 means no time limit) if (($downloads['download_maxdays'] != 0) && ($download_timestamp <= time())) die; // Die if remaining count is <=0 if ($downloads['download_count'] <= 0) die; // Die if file is not there if (!file_exists(OOS_DOWNLOAD_PATH . $downloads['orders_products_filename'])) die; // Now decrement counter $dbconn->Execute("UPDATE " . $oostable['orders_products_download'] . " SET download_count = download_count-1 WHERE orders_products_download_id = '" . intval($_GET['id']) . "'"); // 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['orders_products_filename']); if (DOWNLOAD_BY_REDIRECT == 'true') { // This will work only on Unix/Linux hosts oos_unlink_temp_dir(OOS_DOWNLOAD_PATH_PUBLIC); $tempdir = oos_random_name(); umask(0000); mkdir(OOS_DOWNLOAD_PATH_PUBLIC . $tempdir, 0777); symlink(OOS_DOWNLOAD_PATH . $downloads['orders_products_filename'], OOS_DOWNLOAD_PATH_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename']); oos_redirect(OOS_DOWNLOAD . $tempdir . '/' . $downloads['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 readfile(OOS_DOWNLOAD_PATH . $downloads['orders_products_filename']); }