Home > Backend Development > PHP Tutorial > PHP code to decompress rar files

PHP code to decompress rar files

WBOY
Release: 2016-07-25 08:45:29
Original
1283 people have browsed it

There are many examples of zip files on the Internet. Rar file decompression is not directly supported by php. You can use pecl

Go to http://pecl.php.net/package/rar to download the corresponding version of the non-thread-safe dll

Then throw it into the ext directory of php.

Open php.ini.

Add a line

extension=php_rar.dll

Restart the web server and php

  1. public function _unzip($fileName,$extractTO){
  2. $fileName = iconv('utf-8','gb2312',"upload/zip/August.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 labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template