PHP rar文件解压【原创

来源:https://www.sucaihuo.com/php/1267.html 2017-01-20 07:08浏览(1825) 收藏

本文的教程重点是在rar文件如何在PHP+windows和linux环境下,解压rar文件压缩包。在linux环境下php环境是不支持rar文件解压的。
PHP rar文件解压
分类:PHP > 函数 难易:高级
下载资源 下载积分: 300 积分

linux rar文件解压

http://www.sucaihuo.com/topic/140.html

windows rar文件解压

http://www.sucaihuo.com/topic/147.html

素材火的rar文件windows解压是用的phpstudy本地环境,而且只能支持php5.4

php_rar.dll安装方法如下:

放在 /php/ext/下面,在php.ini中加入一行php_rar扩展引用声明 extension=php_rar.dll。 备注:下载压缩包里有windows php_rar.dll文件。

解压压缩包

$fileName = "demo.rar";

function unrar($fileName, $extractTo) {//$fileName压缩包,$extractTo解压地址
    $rar_file = rar_open($fileName) or die('could not open rar');
    $list = rar_list($rar_file) or die('could not get 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);
}

打印压缩包文件列表

function rar_lists($fileName) { //获取rar压缩文件列表
    $rar_file = rar_open($fileName) or die('could not open rar');
    $list = rar_list($rar_file) or die('could not get list');
    foreach ($list as $file) {
        $pattern = '/\".*\"/';
        preg_match($pattern, $file, $matches, PREG_OFFSET_CAPTURE);
        $pathStr = $matches[0][0];
        $pathStr = str_replace("\"", '', $pathStr);
        $files[] = $pathStr;
    }
    return $files;
}
标签: 压缩解压rar
声明:本文为原创文章,如需转载,请注明来源sucaihuo.com并保留原文链接:https://www.sucaihuo.com/php/1267.html
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2