<?php

/**
 * cPanel'de storage dosyalarini dogrudan sunar.
 * URL: /storage.php?path=listings/1/image.jpg
 * .htaccess ile /storage/xxx -> /storage.php?path=xxx yonlendirmesi yapilir.
 */

$path = $_GET['path'] ?? '';
$path = str_replace(['..', "\0"], '', $path);

$absolutePath = __DIR__ . '/../storage/app/public/' . $path;

if (!$path || !file_exists($absolutePath) || is_dir($absolutePath)) {
    http_response_code(404);
    echo '404 Not Found';
    exit;
}

$mime = mime_content_type($absolutePath) ?: 'application/octet-stream';

header('Content-Type: ' . $mime);
header('Content-Length: ' . filesize($absolutePath));
header('Cache-Control: public, max-age=86400');

readfile($absolutePath);
