prepare($sql); $st->execute([':id'=>$file_id, ':p'=>$praticien_id]); $row = $st->fetch(PDO::FETCH_ASSOC); if (!$row) { http_response_code(403); exit('Forbidden'); } $rel = (string)$row['path']; $abs = rtrim((string)$_SERVER['DOCUMENT_ROOT'], '/').$rel; if (!is_file($abs) || !is_readable($abs)) { http_response_code(404); exit('Not found'); } $mime = $row['mime'] ?: 'application/octet-stream'; $dlName = basename($rel); header('Content-Type: '.$mime); header('Content-Length: '.filesize($abs)); header('Content-Disposition: attachment; filename="'.rawurlencode($dlName).'"'); header('X-Content-Type-Options: nosniff'); readfile($abs);