prepare( 'SELECT file_name, file_mime, file_size, file_path ' . 'FROM admin_chat_messages WHERE id = :id LIMIT 1' ); $stmt->execute([':id' => $id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); $hasFilePath = !empty($row['file_path']); if (!$row || !$hasFilePath) { http_response_code(404); header('Content-Type: text/plain; charset=utf-8'); echo 'Brak pliku'; exit; } if ($hasFilePath) { // Pobierz przez FastAPI (streaming na wyjście) $storedName = basename((string)$row['file_path']); $subfolder = dirname((string)$row['file_path']); try { $fileApi = get_file_api_client(); $fileApi->proxyFile($subfolder, $storedName, $inline === 1); } catch (RuntimeException $e) { $code = (int)$e->getCode(); http_response_code($code === 404 ? 404 : 500); header('Content-Type: text/plain; charset=utf-8'); echo 'Błąd pobierania pliku: ' . $e->getMessage(); } exit; } } catch (Throwable $e) { http_response_code(500); header('Content-Type: text/plain; charset=utf-8'); echo 'Błąd pobierania pliku'; exit; }