Features: - OpenAI Whisper for audio transcription - DeepL API for translation (30+ languages) - Multiple output formats: TXT, VTT, SRT - Flask Python API backend - PHP frontend with black/gold theme - Support for 350MB files - Generates both original and translated files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Download handler for transcribed files
|
|
*/
|
|
|
|
// Prevent any output before headers
|
|
ob_start();
|
|
|
|
// Enable error reporting for debugging
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 0); // Don't display errors, log them
|
|
|
|
if (!isset($_GET['file'])) {
|
|
http_response_code(400);
|
|
die('No file specified');
|
|
}
|
|
|
|
$filename = basename($_GET['file']); // Security: prevent directory traversal
|
|
$filepath = __DIR__ . '/outputs/' . $filename;
|
|
|
|
// Debug logging
|
|
error_log("Download request for: " . $filename);
|
|
error_log("Full path: " . $filepath);
|
|
error_log("File exists: " . (file_exists($filepath) ? 'yes' : 'no'));
|
|
|
|
if (!file_exists($filepath)) {
|
|
http_response_code(404);
|
|
error_log("File not found: " . $filepath);
|
|
die('File not found: ' . $filename);
|
|
}
|
|
|
|
// Check if file is readable
|
|
if (!is_readable($filepath)) {
|
|
http_response_code(403);
|
|
error_log("File not readable: " . $filepath);
|
|
die('File not readable');
|
|
}
|
|
|
|
// Determine content type based on extension
|
|
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
|
$contentTypes = [
|
|
'txt' => '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;
|