PHP压缩文件夹的方法
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 路径都用./这样 解压出来的文件夹就会按照他的来
最新文章
- sharepoint 相关<;httpHandlers>;
- sql对于between和时间
- 启动和关闭ADB服务(adb start-server和adb kill-server)
- PHP--字符串处理函数
- linux查看防火墙状态及开启关闭命令(转)
- IDEA使用docker进行调试
- 获取IMEI码
- TensorFlow深度学习笔记 Tensorboard入门
- Android自动化测试基础知识——MONKEY测试工具(转的)
- 利用ArrayList对Hashtable其进行排序
- httpclient源码分析之MainClientExec
- [LeetCode] Minimum Window Subsequence 最小窗口序列
- 解构领域驱动设计(一):为什么DDD能够解决软件复杂性
- ul的margin撑不开想要的距离的办法
- Redis纠错
- CF817F MEX Queries
- checkbox选中事件的正确写法
- 5、SAMBA服务二:配置实例
- Error:Execution failed for task :app:transformClassesWithInstantRunForDebug解决方案
- 使用Pytorch进行图像分类,AI challenger 农作物病害分类竞赛源码解读