这次给大家带来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 />';
}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>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上就是php解压zip压缩包内容到指定目录步奏详解的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号