PHP zip 解壓縮
在寫PHP時,有時候可能需要讓使用者上傳Zip壓縮文件,在網站中自動解壓縮並提取其中的檔案做解析,可能就需要這個程式囉
需要檔案 PclZip
這份Release的Code實在太簡單了,接下來看到範例就能了解囉
其他請參考 PHPCONCEPT
程式碼
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//匯入pclzip include('pclzip.lib.php'); // 檔案完整路徑 $full_target_path = 'test.zip'; // PclZip $archive = new PclZip($full_target_path); // 資料不存在則產生暫存資料夾(Public all) $destination_path_zip = 'zip/'; if (!file_exists($destination_path_zip)) { mkdir($destination_path_zip, 0777); } // 解壓縮檔案並取得內容列表 $file_list = $archive->extract(PCLZIP_OPT_PATH, $destination_path_zip, PCLZIP_OPT_REMOVE_ALL_PATH); |
臉書留言