php 解压zip压缩包内容到指定目录的实例
作者:iboolean 时间:2024-04-18 09:28:47
目录结构:
test
test/index.php
test/test_zip.zip
test/test_zip
<span style="font-size:14px;"><?php
header('Content-type:text/html;charset=utf-8');
$filename = 'test_zip.zip';
$path = './test_zip.zip';
$dir = 'test_zip';
if(!is_dir($dir)) {
mkdir($dir, 0777, true);//创建目录保存解压内容
}
if(file_exists($filename)) {
$resource = zip_open($filename);
while($zip = zip_read($resource)) {
if(zip_entry_open($resource, $zip)) {
$file_content = zip_entry_name($zip);//获得文件名,mac压缩成zip,解压需要过滤资源库隐藏文件
$file_name = substr($file_content, strrpos($file_content, '/') +1);
if(!is_dir($file_name) && $file_name) {
$save_path = $dir .'/'. $file_name;
if(file_exists($save_path)) {
echo '文件夹内已存在文件 "' . $file_name . '" <pre />';
}else {
echo $file_name . '<pre />';
$file_size = zip_entry_filesize($zip);
$file = zip_entry_read($zip, $file_size);
file_put_contents($save_path, $file);
zip_entry_close($zip);
}
}
}
}
zip_close($resource);
}</span>
来源:http://blog.csdn.net/huangbiubiu/article/details/79115754
标签:php,解压,zip,压缩包,目录
0
投稿
猜你喜欢
python client使用http post 到server端的代码
2021-09-03 14:33:54
Python K最近邻从原理到实现的方法
2022-10-13 09:41:45
Python-for循环的内部机制
2023-02-02 20:47:18
js运算精度丢失的2个解决方法
2024-04-10 10:38:02
xWin之JS版
2009-09-12 18:45:00
Python pandas对excel的操作实现示例
2023-09-25 18:24:13
标准的、语义的、Unobtrusive的页签tab切换
2007-11-03 13:58:00
详解Python的Django框架中的模版相关知识
2023-04-22 02:46:25
交互设计规范原则
2011-09-30 11:52:12
python通配符之glob模块的使用详解
2021-07-16 23:13:18
使用Python脚本生成随机IP的简单方法
2023-12-30 06:46:28
python matplotlib中文显示参数设置解析
2022-11-18 14:11:41
Python利用pynimate实现制作动态排序图
2023-05-25 03:31:32
将Reporting services的RDL文件拷贝到另外一台机器时报Data at the root level is invalid的解决方法
2012-07-11 15:33:45
python实现快速文件格式批量转换的方法
2021-10-31 22:53:12
Python实现K折交叉验证法的方法步骤
2021-08-04 13:58:25
yolov5训练时参数workers与batch-size的深入理解
2021-08-01 04:50:20
python实现集中式的病毒扫描功能详解
2022-03-04 03:16:00
Python3环境安装Scrapy爬虫框架过程及常见错误
2021-10-19 00:01:05
一文详解如何用GPU来运行Python代码
2022-02-26 17:49:30