欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php解壓縮zip和rar壓縮包文件的方法

 更新時(shí)間:2019年07月10日 08:57:45   作者:行星帶  
項(xiàng)目涉及文檔處理,用戶上傳的包括 zip 和 rar 壓縮包,需要先將壓縮包解壓后再作處理。這篇文章主要介紹了php解壓縮zip和rar壓縮包文件,需要的朋友可以參考下

項(xiàng)目涉及文檔處理,用戶上傳的包括 zip 和 rar 壓縮包,需要先將壓縮包解壓后再作處理。對(duì)于 zip 壓縮包,由于 php 自帶 zip 擴(kuò)展,可以直接解壓。

解壓zip壓縮包:

$file = "/opt/data/upload/testfile.zip";
$outPath = "/opt/data/upload/testfile";
$zip = new ZipArchive();
$openRes = $zip->open($file);
if ($openRes === TRUE) {
  $zip->extractTo($outPath);
  $zip->close();
}

對(duì)于 rar 壓縮包,需要先為 php 安裝 rar 擴(kuò)展。

安裝rar擴(kuò)展:

wget http://pecl.php.net/get/rar-4.0.0.tgz
gunzip rar-4.0.0.tgz
tar -xvf rar-4.0.0.tar
cd rar-4.0.0
phpize
./configure && make && make install
# 報(bào)錯(cuò)
configure: error: Cannot find php-config. Please use --with-php-config=PATH
# 運(yùn)行./configure 時(shí)指定php-config路徑即可
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

配置rar擴(kuò)展:

# 新建 /usr/local/php/conf.d/rar.ini,內(nèi)容
extension=rar.so

重啟 php-fpm ,看一下 phpinfo() ;

可以看到已經(jīng)成功安裝了 rar ,可以來(lái)測(cè)試一下解壓 rar 文件。

解壓RAR壓縮包:

$file = "/opt/data/upload/testfile.zip";
$outPath = "/opt/data/upload/testfile";
$rar_file = rar_open($file);
if ($rar_file) {
  $entries = rar_list($rar_file);
  foreach ($entries as $entry) {
    $entry->extract($outPath);
  }
  rar_close($rar_file);
}

這樣就搞定用戶上傳的壓縮包解壓的問(wèn)題了。

總結(jié)

以上所述是小編給大家介紹的php解壓縮zip和rar壓縮包文件的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

最新評(píng)論