prepare('SELECT filename, original_name FROM fortbildung_materials WHERE id = ?'); $stmt->execute([$id]); $row = $stmt->fetch(); if (!$row) { http_response_code(404); echo 'Datei nicht gefunden.'; exit; } $path = dirname(__DIR__) . '/fortbildung-materials/' . $row['filename']; if (!is_file($path)) { http_response_code(404); echo 'Datei nicht gefunden.'; exit; } $safe_display = addslashes($row['original_name']); $safe_encoded = rawurlencode($row['original_name']); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $safe_display . '"; filename*=UTF-8\'\'' . $safe_encoded); header('Content-Length: ' . filesize($path)); header('X-Content-Type-Options: nosniff'); header('Cache-Control: private, no-store'); readfile($path); exit;