我有一个名为' customers'的特定目录。包含各种目录。其中一个目录称为上传。基本上用户更新其内容的位置。此文件夹包含数百张图片。
我想要的是这个特定目录中的所有文件都被添加到一个zip文件中,除了'上传'单独备份的目录。
这是我尝试使用的代码:
$zipFolderExclude = 'customers/uploads/*.*';
// create object
$zip = new ZipArchive();
// open archive
if ($zip->open($zipName, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// initialize an iterator
// pass it the directory to be processed
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($zipFolder));
// iterate over the directory
// add each file found to the archive
foreach ($iterator as $key=>$value) {
if(!is_dir($zipFolderExclude) ) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
echo $key . '<br/>';
}
}
// close and save archive
$zip->close();
echo "Archive created successfully.";
以上代码正在压缩所有文件。我不确定在这个特定代码中该怎么做:
if(!is_dir($zipFolderExclude) ) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
echo $key . '<br/>';
}
如何从zip中排除上传目录?
答案 0 :(得分:1)
由于ZipArchive没有明确支持(某些目录的)排除,您可以应用两种策略: