我使用下面的函数来压缩文件,但在每个目录中它可以自动添加两个文件,如下所示(红色划线)。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'迭代器中将返回模式目录('.'和'..')转义出来。 –