php 解壓rar檔案的代碼

來源:互聯網
上載者:User

對於zip檔案網上的例子很多,rar檔案解壓php沒有直接支援,可以用pecl

到http://pecl.php.net/package/rar 下載對應版本的 非安全執行緒的dll

然後扔到php的 ext目錄下。

開啟php.ini.

加一行

extension=php_rar.dll

重啟web伺服器 和php

  1. public function _unzip($fileName,$extractTO){
  2. $fileName = iconv('utf-8','gb2312',"upload/zip/8月.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. }
複製代碼
php, rar
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.