[英]php zip a folder without looping
with php i can do zip with the following code 用PHP我可以用以下代码压缩
$zip = new ZipArchive;
if ($zip->open ('test.zip', ZipArchive::CREATE)) {
$zip->addFile('img1.jpg', 'user.jpg');
$zip->addFile('logo.jpg', 'file.jpg');
$zip->addFile('avatar.jpg', 'av.jpg');
//or we can even loop a directory
foreach(glob($dir . '/*') as $file)
{
//add each file from the directory
}
//end loop
$zip->close();
echo 'Zipped !';
} else {
echo 'failed';
}
?> ?>
My question is can we zip an entire folder without looping it 我的问题是我们可以压缩整个文件夹而不循环吗
$zip = new ZipArchive;
if ($zip->open ('test.zip', ZipArchive::CREATE)) {
$zip->addFolder('bla bla'); //like this,so that the entire files in it will be added
$zip->close();
echo 'Zipped !';
} else {
echo 'failed';
}
?>
The implementation will have to loop eventually. 最终将不得不循环执行。 Unfortunately ZipArchive
does not expose such a function that will do this for you. 不幸的是, ZipArchive
没有公开将为您执行此功能的函数。
See this thread where you can get a readymade function that does just that. 查看此线程 ,您可以在其中获得完成该任务的现成函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.