0
我正在寻找解压缩文件夹内容的解决方案,其中包括文件夹中的所有子文件夹,但不包括主文件夹本身。压缩文件夹的内容php,而不是整个文件夹
我从这个功能,增加了整个文件夹到一个zip压缩文件
function addFolderToZip($dir, $zipArchive){
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
//Add the directory
$zipArchive->addEmptyDir($dir);
// Loop through all the files
while (($file = readdir($dh)) !== false) {
//If it's a folder, run the function again!
if(!is_file($dir . $file)){
// Skip parent and root directories
if(($file !== ".") && ($file !== "..")){
addFolderToZip($dir . $file . "/", $zipArchive);
}
}else{
// Add the files
$zipArchive->addFile($dir . $file);
}
}
}
}
}
开始,但我不明白如何将功能更改为(可能使用第三个参数?)
$z = new ZipArchive();
$z->open("zips/new.zip", ZIPARCHIVE::CREATE);
addFolderToZip("unzipped/",$z);
$z->close();