\PDO::FETCH_ASSOC, \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" ]); $fileId = isset($_GET['id']) ? intval($_GET['id']) : 0; if ($fileId === 0) { header("HTTP/1.1 404 Not Found"); die; } $sql = "SELECT * FROM mntn_uploads WHERE `id`=:fileId"; $stmt = $db->prepare($sql); if (!$stmt->execute(array('fileId' => $fileId))) { error_log(print_r($stmt->errorInfo(), true)); header("HTTP/1.1 404 Not Found"); die; } $row = $stmt->fetch(); if (!$row) { header("HTTP/1.1 404 Not Found"); die; } $dest = $config['term_logs_root'] . $row['path']; if (!file_exists($dest)) { header("HTTP/1.1 404 Not Found"); die; } Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length: " . $row['file_size']); Header("Content-Disposition: attachment; filename=" . $row['file_name']); readfile($dest); exit();