'text/plain; charset=utf-8', 'vtt' => 'text/vtt; charset=utf-8', 'srt' => 'text/plain; charset=utf-8' // Changed to text/plain for better compatibility ]; $contentType = $contentTypes[$extension] ?? 'application/octet-stream'; // Clear all output buffers while (ob_get_level()) { ob_end_clean(); } // Prevent any caching header('Content-Description: File Transfer'); header('Content-Type: ' . $contentType); header('Content-Disposition: attachment; filename="' . basename($filename) . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($filepath)); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Expires: 0'); // Flush system output buffer flush(); // Output file readfile($filepath); exit;