Php decompress the rarfile and zip file

Source: Internet
Author: User

There are many examples of zip files online, rarfile decompression php is not directly supported, you can use pecl to download the corresponding version of the non-thread-Safe dll http://pecl.php.net/package/rar and then threw it to the php ext directory.

Open php. ini.

Add a row

Extension = php_rar.dll

Restart the web server and php
Copy codeThe Code is as follows:
Public function _ unzip ($ fileName, $ extraceid ){

$ FileName = iconv ('utf-8', 'gb2312', "upload/zip/August .rar ");
// Echo $ fileName. '</br> ';
$ Extractings = "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 ($ extraceid); // extract to the 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.