php安裝php_rar擴展實現(xiàn)rar文件讀取和解壓的方法
本文實例講述了php安裝php_rar擴展實現(xiàn)rar文件讀取和解壓的方法。分享給大家供大家參考,具體如下:
PHP Rar Archiving 模塊 (php_rar) 是一個讀取和解壓rar文件的模塊,但不提供RAR壓縮(打包)的功能。
1.首先要到PECL的RAR頁面下載DLL. 根據(jù)自己的情況選擇下載對應版本的DLL.
PHP版本要求:php_rar模塊適用于php 5.2及以上, 不過對于windows系統(tǒng),似乎只有php5.3 / 5.4對應的DLL下載。
2.下載到的是個zip包,將其中的php_rar.pdb和php_rar.dll兩個文件解壓到PHP安裝目錄下的ext子目錄中。
3.在php.ini中加入一行php_rar擴展引用聲明 extension=php_rar.dll
4.如果使用Apache服務器,就需要重啟Apache。IIS下以FastCGI模式加載的PHP則不需要進一步操作了。
5.寫個測試文件看看有沒有問題啊
6.如果有問題,查看服務器的日志文件。
附官方的測試代碼test-rar.php :
<?php
$archive_name = '/full/path/to/file.rar'
$entry_name = 'path/to/archive/entry.txt'; //notice: no slash at the beginning
$dir_to_extract_to = '/path/to/extract/dir';
$new_entry_name = 'some.txt';
$rar = rar_open($archive_name) OR die('failed to open ' . $archive_name);
$entry = rar_entry_get($rar, $entry_name) OR die('failed to find ' . $entry_name . ' in ' . $archive_name);
// this will create all necessary subdirs under $dir_to_extract_to
$entry->extract($dir_to_extract_to);
/* OR */
// this will create only one new file $new_entry_name in $dir_to_extract_to
$entry->extract('', $dir_to_extract_to.'/'.$new_entry_name);
// this line is really not necessary
rar_close($rar);
?>
更多關于PHP相關內(nèi)容感興趣的讀者可查看本站專題:《PHP擴展開發(fā)教程》、《php文件操作總結(jié)》、《PHP目錄操作技巧匯總》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
相關文章
PHP5.3的垃圾回收機制(動態(tài)存儲分配方案)深入理解
垃圾回收機制是一種動態(tài)存儲分配方案,它會自動釋放程序不再需要的已分配的內(nèi)存塊,PHP也在語言層實現(xiàn)了內(nèi)存的動態(tài)管理.內(nèi)存的動態(tài)管理將開發(fā)人員從繁瑣的內(nèi)存管理中解救出來2012-12-12
php mysql實現(xiàn)mysql_select_db選擇數(shù)據(jù)庫
在PHP中,與MySQL服務器建立連接后,需要確定所要連接的數(shù)據(jù)庫,此時我們可以使用mysql_select_db函數(shù),該函數(shù)用于選擇需要操作的數(shù)據(jù)庫,需要的朋友可以參考下2016-12-12
PHP排序算法之基數(shù)排序(Radix Sort)實例詳解
這篇文章主要介紹了PHP排序算法之基數(shù)排序(Radix Sort),結(jié)合實例形式詳細分析了php基數(shù)排序算法的原理、實現(xiàn)方法與相關使用技巧,需要的朋友可以參考下2018-04-04
PHP實現(xiàn)的消息實時推送功能【基于反ajax推送】
這篇文章主要介紹了PHP實現(xiàn)的消息實時推送功能,結(jié)合實例形式分析了php基于反ajax推送實現(xiàn)的消息實時推送前臺ajax提交、后臺數(shù)據(jù)處理等相關操作技巧,需要的朋友可以參考下2018-03-03
學習php設計模式 php實現(xiàn)單例模式(singleton)
這篇文章主要介紹了php設計模式中的單例模式,使用php實現(xiàn)單例模式,感興趣的小伙伴們可以參考一下2015-12-12

