作者jlshen (买键盘罗)
看板PHP
标题Re: [请益] 解压缩
时间Fri Feb 17 16:53:22 2006
※ 引述《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
1F:推 andreli:感谢 我试试看。 02/18 01:26