createExportZip(); $fileSize = filesize($zipPath); $fileCount = count($controller->getAllThesisFiles()); // Audit log (before headers in case log fails — but it's best-effort anyway) AdminLogger::make()->logFilesExport($fileCount, (int)$fileSize); $filename = 'xamxam-files-' . date('Y-m-d') . '.zip'; header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Length: ' . $fileSize); header('Cache-Control: no-cache, must-revalidate'); readfile($zipPath); // Clean up temp file @unlink($zipPath); } catch (Exception $e) { error_log('Files export error: ' . $e->getMessage()); http_response_code(500); exit('Erreur lors de la création de l\'archive : ' . htmlspecialchars($e->getMessage())); } exit;