getConnection(); $stmt = $pdo->prepare('SELECT * FROM thesis_files WHERE id = ?'); $stmt->execute([$dbId]); $fileRow = $stmt->fetch(); if (!$fileRow) { http_response_code(404); die('Fichier introuvable.'); } $filePath = $fileRow['file_path'] ?? ''; $fileName = $fileRow['file_name'] ?? basename($filePath); $mimeType = $fileRow['mime_type'] ?? 'application/octet-stream'; // ── Skip PeerTube and website entries (no actual file) ─────────────────── if (str_starts_with($filePath, 'peertube_ids:')) { http_response_code(404); die('Fichier PeerTube — pas de flux direct.'); } if (str_starts_with($filePath, 'http://') || str_starts_with($filePath, 'https://')) { http_response_code(404); die('URL — pas de flux direct.'); } // ── Resolve absolute path ──────────────────────────────────────────────── $absPath = STORAGE_ROOT . '/' . $filePath; if (!file_exists($absPath) || !is_readable($absPath)) { http_response_code(404); die('Fichier absent du disque.'); } // ── Stream the file ────────────────────────────────────────────────────── $fileSize = filesize($absPath); // Content-Disposition: inline so FilePond receives it as a valid file header('Content-Type: ' . $mimeType); header('Content-Length: ' . $fileSize); header('Content-Disposition: inline; filename="' . addslashes($fileName) . '"'); header('Cache-Control: no-cache'); readfile($absPath); exit;