有些虚拟空间不支持解压.zip压缩文件,这里使用php语言解压,直接在浏览器执行即可解压压缩包,直接上代码
/**
* php zip文件解压库
* created by dcr163.
* author: dcr163
* date: 2021/09/07
* time: 09:34
*/
class unzip{
public $file; //解压的文件名
public $dist; //解压的目录
public function __construct($file,$dist)
{
if( !$file || !$dist ) throw new errorexception('参数不能为空');
$this->file = $file;
$this->dist = $dist;
}
/**
* 解压zip文件
* @param $file zip文件
* @param $dist 解压的目录
*/
function index(){
if(!class_exists('ziparchive')) throw new errorexception('ziparchive:扩展不存在');
$zip = new ziparchive();
$openres = $zip->open($this->file);
if( $openres === true) {
$stime = $this->formatmicotime(microtime()); //
$res = $zip->extractto($this->dist);
$etime = $this->formatmicotime(microtime());
if( $res ) {
throw new errorexception('解压成功,总花费:'.round($etime-$stime,2).'s');
}
$zip->close();
} else {
throw new errorexception('zip文件打开失败,错误代码:'.$this->ziperrormsg($openres));
}
}
/**
* 错误提示
* @param $code
* @return mixed|string
*/
protected function ziperrormsg($code){
$errorcode = array(
4=>'seek error',
5=>' read error',
9=>'no such file.',
10=>'file already exists.',
11=>'can\'t open file.',
14=>'malloc failure.',
18=>'invalid argument.',
19=>'not a zip archive.',
21=>'zip archive inconsistent',
);
return array_key_exists($code,$errorcode) ? $errorcode[$code] : '未知错误';
}
/**
* 格式化时间戳和微秒数
* @param $microtime
* @return mixed
*/
protected function formatmicotime($microtime){
list($usec,$sec) = explode(' ',$microtime);
return $sec $usec;
}
}
try{
//需要解压的文件
$file = './phpmyadmin4.9.7.zip';
//解压的目录
$dist = 'ad';
$zip = new unzip($file,$dist);
$zip->index();
}catch (exception $e){
exit($e->getmessage());
}
把代码复制,保存到一个php文件里,例如根目录:/unzip.php,最后在浏览器运行www.dcr163.cn/unzip 文件即可。
本文内容来自网友供稿,文章观点仅代表作者本人,本站非盈利且无偿提供信息存储空间服务,不拥有所有权,如有文章有不实信息或侵犯了您的权益,请发送邮件至 cfseo1997@163.com 反馈核实,如需转载请注明出处:https://www.taobobolive.com/23880.html