php 解压rar文件及zip文件的方法

yipeiwu_com6年前PHP代码库
对于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 . '</br>';
$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('</br>entry not found');
$entry->extract($extractTo); // extract to the current dir
}
rar_close($rar_file);

}

相关文章

PHP实现的策略模式示例

本文实例讲述了PHP实现的策略模式。分享给大家供大家参考,具体如下: 个人觉得设计模式只有在实际应用中才能够慢慢的去熟悉,到最后做到心中有模式,事事有模式,哈哈 例如:一个电商首页,...

PHP递归创建多级目录

PHP递归创建多级目录

我的第一个感觉就是用递归创建,具体思路如下: function Directory($dir){     if(is_dir($dir) || @mkdir($dir,0777))...

PHP+jQuery实现即点即改功能示例

PHP+jQuery实现即点即改功能示例

本文实例讲述了PHP+jQuery实现即点即改功能。分享给大家供大家参考,具体如下: <!DOCTYPE html> <html lang="en"> <...

php自定义扩展名获取函数示例

本文实例讲述了php自定义扩展名获取函数。分享给大家供大家参考,具体如下: <?php $url = "http://www.abc.com/abc/de/fg.php...

php导出生成word的方法

本文实例讲述了php导出生成word的方法。分享给大家供大家参考,具体如下: PHP导出word (1)首先,预览html页面,示例化对象,定义要导出的数据 (2)点击下载页面,给id传...