php解壓zip檔案

來源:互聯網
上載者:User

標籤:

php實現解壓zip檔案

 1 function zip($filename, $path) 2 { 3 //        $filename = ‘test.zip‘; 4 //        $path = ‘./document/2016-05-11/test.zip‘; 5     $path_all = $_SERVER[‘DOCUMENT_ROOT‘] . sp_get_asset_upload_path(mb_substr($path, 2));//think_cmf的擷取檔案路勁 6     $file_name_head = mb_substr($path, 0, strrpos($path, "/")); 7     if (!file_exists($path_all)) { 8         echo ‘檔案不存在‘; 9     }10     //z轉碼  將檔案名稱和路徑轉成windows系統預設的gb2312編碼,否則將會讀取不到11     $filename = iconv(‘utf-8‘, ‘gb2312‘, $filename);12     $path_all = iconv(‘utf-8‘, ‘gb2312‘, $path_all);13     //開啟壓縮包14     $resource = zip_open($path_all);15     $i = 0;16     while ($dir_resource = zip_read($resource)) {17         if (zip_entry_open($resource, $dir_resource)) {18             $file_name = substr($path_all, 0, strrpos($path_all, "/")) . ‘/‘ . zip_entry_name($dir_resource);19             $dir_name = zip_entry_name($dir_resource);20             $file_path = substr($file_name, 0, strrpos($file_name, "/"));21         }22         if (!is_dir($file_path)) {23             mkdir($file_path, 0777, true);24         }25         if (!is_dir($file_name)) {26             $file_size = zip_entry_filesize($dir_resource);27             //最大讀取10M,如果檔案過大,跳過解壓,繼續下一個28             if ($file_size < (1024 * 1024 * 10)) {29                 $file_content = zip_entry_read($dir_resource, $file_size);30                 file_put_contents($file_name, $file_content);31             }32             //關閉當前33             zip_entry_close($dir_resource);34         }35         $dir_name = iconv(‘gb2312‘, ‘utf-8‘, $dir_name);36         $data[$i][filename] = $file_name_head . ‘/‘ . $dir_name;37         $data[$i][‘size‘] = $file_size;38         $i++;39     }40     zip_close($resource);41     return $data;42 }

 

php解壓zip檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.