这次给大家带来php解压zip压缩包内容到指定目录步奏详解,php解压zip压缩包内容到指定目录的注意事项有哪些,下面就是实战案例,一起来看一下。
本文给大家介绍了php解压zip压缩包内容到指定目录的代码,有需要的朋友可以参考一下。
目录结构:
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 class="brush:php;toolbar:false;" />';
}else {
echo $file_name . '<pre class="brush:php;toolbar:false;" />';
$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>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
易优建站家政保洁服务类深色网站源码是基于易优cms开发,非常适合服务类企业通过网络拓展业务、程序内核为Thinkphp5.0开发,后台简洁,为企业网站而生。这是一套安装就能建站的程序,不定期更新程序BUG,更新网站功能。我们提供的不仅是模板这么简单,我们还提供程序相关咨询、协助安装等服务。默认不包含小程序插件,需要另外单独购买插件。★模板安装步骤★1、请将安装包ZIP上传到你的网站根目录,在线解压
0
以上就是php解压zip压缩包内容到指定目录步奏详解的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号