Code for extracting RAR files from PHP

Source: Internet
Author: User

For the zip file online example many, RAR file decompression PHP no direct support, you can use PECL

To Http:// download the corresponding version of the non-thread-safe DLL

Then throw it into the ext directory of PHP.

Open php.ini.

Add a row


Restarting the Web server and PHP

    1. Public Function _unzip ($fileName, $extractTO) {
    2. $fileName = iconv (' utf-8 ', ' gb2312 ', "Uploa D/ZIP/8 months. rar ");
    3. //Echo $fileName. '
    4. $extractTo = "upload/zip/test/";
    5. $rar _file = Rar_open ($fileName) or die (' could not open rar ');
    6. $list = rar_list ($rar _file) or die (' could not get list ');
    7. //Print_r ($list);
    8. foreach ($list as $file) {
    9. $pattern = '/\ '. *\ "/";
    10. Preg_match ($pattern, $file, $matches, preg_offset_capture);
    11. $pathStr = $matches [0][0];
    12. $pathStr =str_replace ("\" "," ', $pathStr);
    13. //Print_r ($PATHSTR);
    14. $entry = Rar_entry_get ($rar _file, $pathStr) or Die ('
      Entry not found ');
    15. $entry->extract ($extractTo);//extract to the current dir
    16. }
    17. rar_close ($rar _file);
    18. }
Copy Code
PHP, rar
  • Related Article

    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: 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.