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 );
}