I found a great solution on how to ZIP folders and files on my server, but how do I make the script exclude the folder /archiv and all of its subfolders?
$backup_file = $_SERVER['DOCUMENT_ROOT'].'/archiv/system/system_' . date("Y-m-d-H-i-s") . '.zip';
$zip = new ZipArchive();
$zip->open($backup_file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($_SERVER['DOCUMENT_ROOT']),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
if($file == 'archiv'){
continue;
}else{
// Skip directories (they would be added automatically)
if (!$file->isDir()){
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
$zip->addFile($filePath, $relativePath);
}
}
}
$zip->close();
Many thanks for any help!