<?php include 'utilities.php'; $folder = $_POST['folder']; $name = $_POST['name']; $zip = $folder . "/" . $name . ".zip"; if (file_exists($zip)) { unlink($zip); } try { App_File_Zip::CreateFromFilesystem($folder, $zip); rrmDirOlderThan('../../temps'); } catch (App_File_Zip_Exception $e) { // Zip file was not created. echo "Le zip n'as pu être créé."; }
private function downloadAsZip() { try { $finalSrc = $this->templatesDir . '/' . $this->templateName . '/'; $zipName = $this->templateName . "-" . time() . ".zip"; $tmpDest = $this->workingDirectory . $zipName; App_File_Zip::CreateFromFilesystem($finalSrc, $tmpDest); // Destroy the final src destroyDir($finalSrc); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($zipName) . '"'); header('Content-Length: ' . filesize($tmpDest)); readfile($tmpDest); // Remove the unpacks directory destroyDir($this->workingDirectory . $this->templateName); // Remove zip from the tmp dir unlink($tmpDest); } catch (App_File_Zip_Exception $e) { // Zip file was not created. destroyDir($finalSrc); } }