Home > php教程 > php手册 > body text

php教程:如何解压压缩包

WBOY
Release: 2016-06-06 20:09:41
Original
1778 people have browsed it

有时候啊,看到一个主机蛮不错的说,然后一冲动,你就买下来。买下来发现控制面板功能弱爆了,连个在线解压的功能都没有,那真的叫一个后悔

有时候啊,看到一个主机蛮不错的说,然后一冲动,你就买下来。买下来发现控制面板功能弱爆了,连个在线解压的功能都没有,那真的叫一个后悔啊。确实,在线解压缩可以非常便捷地完成部署网站数据的一个任务,如果文件多又大,那先上传再在线解压肯定要更快的,虽说并不是什么必备功能,但是如果缺失了这个功能,那真是不方便。主机上禁用了这个或者没有这个功能的话,那我们手动地添加这个功能吧。

php解压函数

<?php ? ??
function?unzip($location,$newLocation){? ??
????????if(exec("unzip?$location",$arr)){? ??
????????????mkdir($newLocation);? ??
????????????for($i?=?1;$i<?count($arr);$i++){? ??
????????????????$file?=?trim(preg_replace("~inflating:?~","",$arr[$i]));? ??
????????????????copy($location.'/'.$file,$newLocation.'/'.$file);? ??
????????????????unlink($location.'/'.$file);? ??
????????????}? ??
????????????return?TRUE;? ??
????????}else{? ??
????????????return?FALSE;? ??
????????}? ??
????}? ??
?>??
Copy after login

使用方法

if(unzip('zipedfiles/test.zip','unziped/myNewZip'))? ??
????echo?'解压成功!';? ??
else? ??
????echo?'未知原因?错误鸟';???
Copy after login

声明: 本文采用 BY-NC-SA 协议进行授权 | IT路人
转载请注明转自《php教程:如何解压压缩包》

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!