PHP automatically decompress the uploaded rarfile

Source: Internet
Author: User
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

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.