\n"; $id = (int)$_REQUEST['id']; if ($id > 0) { include("config/config.php"); include("./includes/globals.php"); $_data = sql("SELECT FileName, Published FROM Documents WHERE DocumentId = '$id' "); if ($_data['num_rows'] > 0) { if ($_data['data'][0]['Published'] != 1) echo "Document is no longer published"; else { $filename = "$root_path/documents/{$_data['data'][0]['FileName']}"; Header("Content-Type: ". mime_content_type($filename)); Header("Content-Length: ". filesize($filename)); Header('Content-Disposition: attachment; filename="'.basename($filename).'"'); ob_clean(); flush(); try { #$filename = '/home/vhosts/franceslincoln.com/httpdocs/favicon.ico'; $handle = fopen($filename, 'rb'); if ($handle === false) { throw new Exception('failed to open file'); } while (!feof($handle)) { $buffer = fread($handle, 32 * 1024); print $buffer; } # flush(); fclose($handle); #readfile was running out of memory on large files #readfile($filename); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } sql("UPDATE Documents SET Downloads = Downloads + 1 WHERE DocumentId = '$id' LIMIT 1"); } } } ?>