如何使用php从ZIP文件生成中排除文件夹?

时间:2015-05-08 13:38:00

标签: php ziparchive

我找到了关于如何在我的服务器上压缩文件夹和文件的great solution,但是如何让脚本排除文件夹/存档及其所有子文件夹?

$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();

非常感谢您的帮助!

0 个答案:

没有答案
相关问题