Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn. We all know that php has a zip class that allows you to directly operate zip files, however, users sometimes have to upload rar compressed files, and we cannot force users to upload only zip files, so the problem arises. How to decompress the rarfile?
When the problem arises, there will be solutions and ways to solve it. The following yunge network will explain to you how to decompress rar compressed files using php.
There are two methods. One is to use php to expand php_rar, and the other is to call the php com component for decompression. The following describes the implementation methods and procedures in sequence!
First, use php_rar to expand and decompress rar
$ Rar_file = rar_open('test.rar ') or die ("Failed to open Rar archive ");
$ Rar_file-> extract ($ extracact );
2
Second, decompress the rarfile using the php com component.
Function unrar ($ file, $ dir ){
If ($ obj = new com ("wscript. shell ")){
$ Obj-> run ('winrar x E: \ web \ '. $ file. ''. 'd: \ web \'. $ dir, 0, true );
Return true;
} Else {
Return false;
}
}
$ FileIndicates the name of the file to be decompressed. An absolute path is required.
$ DirIndicates the path to be decompressed.
From: yunge Network | http://www.zioor.com/view/1667
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB