1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-25 20:57:25 +02:00

Optimisation des téléchargements ZIP

This commit is contained in:
Yohann
2019-09-09 12:15:48 +02:00
committed by galaxyoyo
parent 190039a5e8
commit 57d2bb9bec
7 changed files with 90 additions and 59 deletions

View File

@ -4,35 +4,14 @@
if (isset($_POST["download_zip"])) {
$id = $_POST["tournament"];
$tournament = Tournament::fromId($id);
$syntheses = $tournament->getAllSyntheses();
$zip = new ZipArchive();
$temp = tempnam("tmp", "tfjm-");
if ($zip->open($temp, ZipArchive::CREATE) !== true) {
die("Impossible de créer le fichier zip.");
}
/** @var Synthesis $synthesis */
foreach ($syntheses as $synthesis) {
$file_id = $synthesis->getFileId();
$dest = $synthesis->getDest();
$version = $synthesis->getVersion();
$team = Team::fromId($synthesis->getTeamId());
$team_name = $team->getName();
$team_trigram = $team->getTrigram();
$zip->addFile("$LOCAL_PATH/files/$file_id", "Note de synthèse $team_trigram pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf");
}
$zip->close();
$file_name = getZipFile(DocumentType::SYNTHESIS, $id);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"Notes de syntèses du tournoi de " . $tournament->getName() . ".zip\"");
header("Content-Length: " . filesize($temp));
header("Content-Length: " . filesize($file_name));
readfile($temp);
readfile($file_name);
exit();
}