Home > Backend Development > PHP Tutorial > php 解压rar文件及zip文件的方法_php技巧

php 解压rar文件及zip文件的方法_php技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-17 08:44:39
Original
960 people have browsed it

对于zip文件网上的例子很多,rar文件解压php没有直接支持,可以用pecl到http://pecl.php.net/package/rar 下载对应版本的 非线程安全的dll然后扔到php的 ext目录下。

打开php.ini.

加一行

extension=php_rar.dll

重启web服务器 和php

复制代码 代码如下:

public function _unzip($fileName,$extractTO){

$fileName = iconv('utf-8','gb2312',"upload/zip/8月.rar");
// echo $fileName . '';
$extractTo = "upload/zip/TEST/";

$rar_file = rar_open($fileName) or die('could not open rar');
$list = rar_list($rar_file) or die('could not get list');
// print_r($list);



foreach($list as $file) {
$pattern = '/\".*\"/';
preg_match($pattern, $file, $matches, PREG_OFFSET_CAPTURE);
$pathStr=$matches[0][0];
$pathStr=str_replace("\"",'',$pathStr);
// print_r($pathStr);
$entry = rar_entry_get($rar_file, $pathStr) or die('entry not found');
$entry->extract($extractTo); // extract to the current dir
}
rar_close($rar_file);

}
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template