php 解壓rar文件及zip文件的方法
更新時間:2014年05月05日 16:50:37 作者:
rar文件解壓php沒有直接支持的,不過可以通過下載將非線程安全的dll然后扔到php的ext目錄下,之后按照下面的步驟操作即可
對于zip文件網(wǎng)上的例子很多,rar文件解壓php沒有直接支持,可以用pecl到http://pecl.php.net/package/rar 下載對應(yīng)版本的 非線程安全的dll然后扔到php的 ext目錄下。
打開php.ini.
加一行
extension=php_rar.dll
重啟web服務(wù)器 和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.ini.
加一行
extension=php_rar.dll
重啟web服務(wù)器 和php
復(fù)制代碼 代碼如下:
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);
}
相關(guān)文章
基于PHP實現(xiàn)短信驗證碼發(fā)送次數(shù)限制
這篇文章主要介紹了基于PHP實現(xiàn)短信驗證碼發(fā)送次數(shù)限制,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07php實現(xiàn)有序數(shù)組打印或排序的方法【附Python、C及Go語言實現(xiàn)代碼】
這篇文章主要介紹了php實現(xiàn)有序數(shù)組打印或排序的方法,涉及php針對數(shù)組的遍歷、判斷、構(gòu)造與合并等常用操作技巧,并附帶了Python、C及Go語言的實現(xiàn)代碼,需要的朋友可以參考下2016-11-11給PHP開發(fā)者的編程指南 第一部分降低復(fù)雜程度
給PHP開發(fā)者的編程指南,第一部分的內(nèi)容是降低復(fù)雜程度,感興趣的小伙伴們可以參考一下2016-01-01php中time()與$_SERVER[REQUEST_TIME]用法區(qū)別
這篇文章主要介紹了php中time()與$_SERVER[REQUEST_TIME]用法區(qū)別,詳細(xì)分析了time()與$_SERVER[REQUEST_TIME]的用法,并以實例形式對比總結(jié)了二者在獲取當(dāng)前系統(tǒng)時間戳與請求時間戳的區(qū)別,需要的朋友可以參考下2014-11-11