我有一個名爲'customers'的特定目錄,其中包含各種目錄。其中一個目錄稱爲uploads。基本上用戶更新他們的內容。該文件夾包含數百張照片。PHP排除郵編中包含的特定目錄
我想要的是,這個特定目錄中的所有文件都被添加到一個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的上傳目錄,好嗎?
也許'if($ value!= $ zipFolderToExclude)'而不是?現在你正在檢查你的zip文件夾是否是一個文件夾(呵呵,這是...),然後把它加到你的zip文件中。 –
@MarcB - 我試過你的解決方案。它沒有工作。 – user3173207