Pclzip 使用入门
实例一,创建压缩文件:
include_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
$v_list = $archive->create('file.txt,data/text.txt,folder');
if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
}
实例二,解压文件:
require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
if ($archive->extract() == 0) {
die("Error : ".$archive->errorInfo(true));
}
实例三,解压部分文件:
require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
if ($archive->extract(PCLZIP_OPT_BY_NAME, $fiel_list) == 0) {
die("Error : ".$archive->errorInfo(true));
}
实例四,获取压缩文件列表:
$zip = new PclZip("test.zip");
if (($list = $zip->listContent()) == 0) {
die("Error : ".$zip->errorInfo(true));
}
if (($list = $zip->listContent()) == 0) {
die("Error : ".$zip->errorInfo(true));
}
for ($i=0; $i<sizeof($list); $i++) {
for(reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
echo "File $i / [$key] = ".$list[$i][$key]." ";
}
echo "";
for(reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
echo "File $i / [$key] = ".$list[$i][$key]." ";
}
echo "";