温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php 解压zip压缩包内容到指定目录的实例

发布时间:2020-10-17 12:21:28 来源:脚本之家 阅读:222 作者:iboolean 栏目:web开发

目录结构:

test

test/index.php
test/test_zip.zip
test/test_zip

<span ><?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 解压zip压缩包内容到指定目录的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI