How to decompress rar files and zip files in php_PHP tutorial

WBOY
Release: 2016-07-13 10:30:34
Original
1043 people have browsed it

There are many examples of zip files on the Internet. Rar file decompression is not directly supported by php. You can use pecl to http://pecl.php.net/package/rar to download the corresponding version of the non-thread-safe dll and then throw it into the ext directory of php. .

Open php.ini.

Add a line

extension=php_rar.dll

Restart the web server and php

Copy code The code is as follows:

public function _unzip($fileName,$extractTO){

$fileName = iconv('utf-8' ,'gb2312',"upload/zip/August.rar");
// echo $fileName . '
';
$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('
entry not found');
$entry->extract($extractTo); // extract to the current dir
}
rar_close($rar_file);

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/765156.htmlTechArticleThere are many examples on the Internet for zip files. Rar file decompression is not directly supported by php. You can use pecl to http:// pecl.php.net/package/rar Download the corresponding version of the non-thread-safe dll and throw it to...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template