Extracting the rarfile from php is not directly supported. However, you can download a non-thread-safe dll and then drop it to the php ext directory, then, follow the steps below to find many examples on the zip file website. The rarfile unzipping php is not directly supported, you can use pecl to download the corresponding version of the non-thread-safe dll to the http://pecl.php.net/package/rar and then drop it into the php ext directory.
Open php. ini.
Add a row
Extension = php_rar.dll
Restart the web server and php
The code is as follows:
Public function _ unzip ($ fileName, $ extraceid ){
$ FileName = iconv ('utf-8', 'gb2312', "upload/zip/August .rar ");
// Echo $ fileName .'
';
$ 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 ('
Entry not found ');
$ Entry-> extract ($ extraceid); // extract to the current dir
}
Rar_close ($ rar_file );
}