. */ require_once(__DIR__ . '/../conf.php'); $filename = $_REQUEST['name']; $filepath = Constants::files_folder . $filename; $key = $_REQUEST['key']; $files = File::search($_pdo, ['`filename`=?'], [$filename]); if (count($files) == 0 || !file_exists($filepath) || is_dir($filepath)) { http_response_code(404); header('Content-type: text/plain'); echo "$filename could not be found"; } elseif (array_pop($files)->secret_key != $key) { http_response_code(403); header('Content-type: text/plain'); echo "incorrect key"; } else { header('Content-type: ' . mime_content_type($filepath)); header('Content-Disposition: attachment; filename="'.$filename.'"'); readfile($filepath); }