我使用下面的函數來壓縮文件,但在每個目錄中它可以自動添加兩個文件,如下所示(紅色劃線)。PHP Ziparchive主機上的Linux
如何在排除這些不需要的文件的同時壓縮文件?
function ziparchive($name,$folder){
// create object
$ziparchivename= $name.'.zip';
//echo $ziparchivename;
$zip = new ZipArchive();
// open archive
if ($zip->open($ziparchivename, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// initialize an iterator
// pass it the directory to be processed
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder));
// iterate over the directory
// add each file found to the archive
foreach ($iterator as $key=>$value) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}
// close and save archive
$zip->close();
echo "Archive created successfully.";
}
嘗試在'foreach'迭代器中將返回模式目錄('.'和'..')轉義出來。 –