PHP压缩文件夹的方法
<pre>
public function addFileToZip($path, $zip)
{
$handler = opendir($path); //打开当前文件夹由$path指定。
while (($filename = readdir($handler)) !== false) {
if ($filename != "." && $filename != "..") {
//文件夹文件名字为'.'和‘..',不要对他们进行操作
if (is_dir($path . "/" . $filename)) {
// 如果读取的某个对象是文件夹,则递归
$this->addFileToZip($path . "/" . $filename, $zip);
} else {
//将文件加入zip对象
$zip->addFile($path . "/" . $filename);
}
}
}
closedir($path);
}

public function testyasuo()
{

$zip = new \ZipArchive();
$xiangmupath = $this->getxiangmupath();
$filename = './moban/css.zip';

if ($zip->open($filename, \ZipArchive::OVERWRITE) === true) {

$zip->addFile('./moban/email.xlsx', 'email.xlsx');
$this->addFileToZip('./moban/css/', $zip);
$zip->close(); //关闭处理的zip文件
}

}
</pre>
ps:
1 这个PHP是自带的不需要装php_zip扩展模块
2 如果没有zip没创建 如果有了就会覆盖
3 创建好zip 一定要添加文件到zip 不然创建不了zip
4 路径都用./这样 解压出来的文件夹就会按照他的来

最新文章

  1. sharepoint 相关&lt;httpHandlers&gt;
  2. sql对于between和时间
  3. 启动和关闭ADB服务(adb start-server和adb kill-server)
  4. PHP--字符串处理函数
  5. linux查看防火墙状态及开启关闭命令(转)
  6. IDEA使用docker进行调试
  7. 获取IMEI码
  8. TensorFlow深度学习笔记 Tensorboard入门
  9. Android自动化测试基础知识——MONKEY测试工具(转的)
  10. 利用ArrayList对Hashtable其进行排序
  11. httpclient源码分析之MainClientExec
  12. [LeetCode] Minimum Window Subsequence 最小窗口序列
  13. 解构领域驱动设计(一):为什么DDD能够解决软件复杂性
  14. ul的margin撑不开想要的距离的办法
  15. Redis纠错
  16. CF817F MEX Queries
  17. checkbox选中事件的正确写法
  18. 5、SAMBA服务二:配置实例
  19. Error:Execution failed for task :app:transformClassesWithInstantRunForDebug解决方案
  20. 使用Pytorch进行图像分类,AI challenger 农作物病害分类竞赛源码解读

热门文章

  1. 从.NET CORE2.2升级到3.0过程及遇到的一些问题
  2. Vue-cli中axios传参的方式以及后端取的方式
  3. .NET北京俱乐部,技术的饕餮盛宴,不枉此行
  4. Codeforces1141F_Same Sum Blocks
  5. Cymothoa后门工具
  6. JS中作用域和作用域链
  7. POST PUT 小解
  8. 生产环境中利用软链接避免&quot;rm -rf /&quot;的方法
  9. 微信企业号开发入门(回调模式)java
  10. 浏览器标签tab窗口切换时事件状态侦听