Heim  >  Artikel  >  php教程  >  php教程:如何解压压缩包

php教程:如何解压压缩包

WBOY
WBOYOriginal
2016-06-06 20:09:411780Durchsuche

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

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

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;? ??
????????}? ??
????}? ??
?>??

使用方法

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

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP 正则表达式简单笔记Nächster Artikel:PHP内网端口扫描脚本