How to extract RAR files and zip files in php _php tips

Source: Internet
Author: User
Tags rar
For the zip file on the web, a lot of examples, RAR file decompression PHP does not have direct support, you can use PECL to Http://pecl.php.net/package/rar download the corresponding version of the non-thread-safe DLL and then throw to the PHP ext directory.

Open php.ini.

Add one line

Extension=php_rar.dll

Restart the Web server and PHP
Copy Code code as follows:

Public function _unzip ($fileName, $extractTO) {

$fileName = Iconv (' u Tf-8 ', ' gb2312 ', "Upload/zip/8 month. 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 "Current dir
}
Rar_close ($rar _file);

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.