<?php
require_once __DIR__ . '/includes/functions.php';
$id = (int)($_GET['id'] ?? 0);
$item = getRelease($id);
if(!$item){http_response_code(404); exit('File not found.');}
$path = safeDownloadPath($item['file_path']);
if(!$path){http_response_code(404); exit('File not found.');}
incrementDownload($id);
$filename = basename($path);
$mime = function_exists('mime_content_type') ? mime_content_type($path) : 'application/octet-stream';
if(!$mime) $mime='application/octet-stream';
header('Content-Description: File Transfer');
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.addcslashes($filename,'"\\').'"');
header('Content-Length: '.filesize($path));
header('Cache-Control: private, no-transform, no-store, must-revalidate');
header('X-Content-Type-Options: nosniff');
readfile($path); exit;
