[英]PHP Exclude particular directories from being included in Zip
我有一個名為“客戶”的特定目錄,其中包含各種目錄。 目錄之一稱為上載。 基本上是用戶更新其內容的地方。 此文件夾包含數百張圖片。
我想要的是將這個特定目錄中的所有文件都添加到一個zip文件中,除了單獨備份的“ uploads”目錄。
這是我嘗試使用的代碼:
$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中排除上載目錄?
由於ZipArchive不明確支持(某些目錄中的)排除,因此您可以應用兩種策略:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.