|
<?php |
|
|
|
|
|
|
|
|
|
error_reporting(E_ALL); |
|
ini_set('display_errors', 1); |
|
|
|
|
|
$folders = [ |
|
'data', |
|
'EMIL', |
|
'EMILS', |
|
'BUY', |
|
'assignment', |
|
]; |
|
|
|
|
|
$zip = new ZipArchive(); |
|
$zipFilename = 'all_content.zip'; |
|
|
|
if ($zip->open($zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) { |
|
die("Could not open archive"); |
|
} |
|
|
|
|
|
foreach ($folders as $folder) { |
|
|
|
addFolderToZip($folder, $zip); |
|
} |
|
|
|
|
|
$zip->close(); |
|
|
|
|
|
header('Content-Type: application/zip'); |
|
header('Content-Disposition: attachment; filename=' . basename($zipFilename)); |
|
header('Content-Length: ' . filesize($zipFilename)); |
|
readfile($zipFilename); |
|
|
|
|
|
unlink($zipFilename); |
|
exit(); |
|
|
|
|
|
function addFolderToZip($folder, $zipArchive, $zipPath = '') { |
|
|
|
$currentZipPath = rtrim($zipPath . '/' . basename($folder), '/'); |
|
|
|
|
|
$zipArchive->addEmptyDir($currentZipPath); |
|
|
|
|
|
$files = scandir($folder); |
|
foreach ($files as $file) { |
|
if ($file === '.' || $file === '..') { |
|
continue; |
|
} |
|
$filePath = "$folder/$file"; |
|
if (is_dir($filePath)) { |
|
|
|
addFolderToZip($filePath, $zipArchive, $currentZipPath); |
|
} else { |
|
|
|
$zipArchive->addFile($filePath, "$currentZipPath/$file"); |
|
} |
|
} |
|
} |
|
|