看板 PHP 關於我們 聯絡資訊
※ 引述《andreli (第一次賭P幣就沒錢)》之銘言: : 請問一下在解壓縮的過程中,怎麼辨別遇到的是資料夾呢? : 因為現在在做一個上傳程式 : 如果遇到資料夾的話解壓縮就會出錯 : 所以我想遇到資料夾的話就把它跳過去不解開 : 請問該怎麼辨別遇到的是資料夾呢? : 又或者有人有寫過如實解壓縮整個檔案的程式嗎? : (就是遇到資料夾會新增資料夾,連此資料夾底下的資料也會一併解壓縮) : 謝謝幫忙,謝謝。 我用的是這套 PclZip http://www.phpconcept.net/pclzip/man/en/index.php 底下是自己在用的 function function uncompress($file,$descdir){ include_once "pclerror.lib.php"; include_once "pcltrace.lib.php"; include_once "pclzip-trace.lib.php"; $zip = new PclZip($file); $only_dir = "Y"; if (($list = $zip->listContent()) == 0) { die("Error : ".$zip->errorInfo(true)); } for ($i=0;$i<count($list);$i++){ $sub = strstr($list[$i][filename],"/"); $dirname[] = str_replace($sub,"",$list[$i]["filename"]); if (!$sub) $only_dir = "N"; } if (count(array_unique($dirname)) == 1 && $only_dir == "Y"){ $remove_dir = $dirname[0]; }else{ $remove_dir = ""; } if ($zip->extract(PCLZIP_OPT_PATH, $descdir, PCLZIP_OPT_REMOVE_PATH, $remove_dir) == 0) { die("Error : ".$archive->errorInfo(true)); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.23.214.146
andreli:感謝 我試試看。 02/18 01:26