php解壓縮zip和rar壓縮包檔案的方法

2022-09-26 05:15:10 字數 1229 閱讀 1173

專案涉及文件處理,使用者上傳的包括 zip 和 rar 壓縮包,需要先將壓縮包解壓後再作處理。對於 zip 壓縮包,由於 php 自帶 zip 擴充套件,可以直接解壓。

解壓zip壓縮包:

$file = "/opt/data/upload/testfile.zip";

$outpath = "/opt/data/upload/testfile";

$zip = new ziparchive();

$openres = $zip->open($file);

if ($openres === true)

對於 rar 壓縮包,需要先為 php 安裝 rar 擴充套件。

安裝rar擴充套件:

wget

gunwww.cppcns.comzip rar-4.0.0.tgz

tar -xvf rar-4www.cppcns.com.0.0.tar

cd rar-4.0.0

phpize

./configure && make && make install

# 報錯

configure: error: cannot find php-config. please use --with-php-config=path

# 執行./c程式設計客棧onfigure 時指定php-config路徑即可

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

配置rar擴充套件:

# 新建 /usr/local/php/conf.d/rar.ini,內容

extension=rar.so

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

可以看到已經成功安裝了 rar ,可以來測試一下解壓 rar 檔案。

解壓rar壓縮包:

$file = "/opt/data/upload/testfile.zip";

$outpath = "/opt/data/upload/testfile";

$rar_file = rar_open($file);

if ($rar_file)

rar_close($rar_file);

}這樣就搞定使用者上傳的壓縮包解壓的問題了。

總結本文標題: php解壓縮zip和rar壓縮包檔案的方法

本文位址: /wangluo/php/265077.html

PHP執行zip與rar解壓縮方法

所謂萬事開頭難,php的編寫也是這樣,因此,今天為您介紹一些php執行zip與rar解壓縮方法的應用技巧給大家作參考,希望對大家有所幫助。zip pclzip net pclzip index.en.php rar pecl rar 過去要在php下執行解壓縮程式,無非最常見的方法是寫command...

PHP 解壓縮zip檔案

1 使用php執行檔案解壓縮zip檔案,前提條件,一定要確定伺服器開啟了zip拓展 2 封裝的方法如下 例項 1 3 壓縮檔案 4 param array files 待壓縮檔案 array d test 1.txt d test 2.jpg 檔案位址為絕對路徑 5 param string fil...

Linux 壓縮 解壓縮RAR檔案

安裝 sudo apt get install unrar 解除安裝 sudo apt get remove unrar e將檔案解壓到當前目錄 例 rar e test.rar 注 用e解壓的話,不僅原來的file1.txt和file2.txt被解壓到當前目錄,就連dir1裡面的所有檔案也被解壓到...