file($realFull); $allowedMimes = [ 'image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'video/mp4', 'application/zip', ]; if (!in_array($mimeType, $allowedMimes, true)) { http_response_code(403); exit; } // --- 4. Send response headers ------------------------------------------------- header('Content-Type: ' . $mimeType); header('Content-Length: ' . filesize($realFull)); header('X-Content-Type-Options: nosniff'); $ext = strtolower(pathinfo($realFull, PATHINFO_EXTENSION)); if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif'], true)) { // Images: cache publicly for 7 days header('Cache-Control: public, max-age=604800'); } elseif ($ext === 'pdf') { // PDFs: cache for 1 day, display inline header('Cache-Control: public, max-age=86400'); header('Content-Disposition: inline'); } else { // Everything else: no public caching header('Cache-Control: private, no-store'); } // --- 5. Stream file ----------------------------------------------------------- readfile($realFull);