php_zip扩展讲解之zip函数
1、打开/关闭zip资源文件
resource zip_read ( resource $zip )
void zip_close ( resource $zip ) 关闭zip资源
2、逐步获取zip压缩包中的条目
resource zip_read ( resource $zip )
3、获取条目名称,实际大小和压缩后的大小
string zip_entry_name ( resource $zip_entry ) 返回条目名称
int zip_entry_filesize ( resource $zip_entry ) 返回条目实际大小
int zip_entry_compressedsize ( resource $zip_entry ) 返回条目压缩后的大小
4、关闭条目资源
bool zip_entry_close ( resource $zip_entry )
1、$zip = zip_open("demo.zip");
if($zip == true){
$html ="<table><tr><th>名称</th><th>实际大小</th><th>压缩大小</th></tr>";
while ($entry = zip_read($zip)) {
$html .="<tr><td>".zip_entry_name($entry)."</td><td>".zip_entry_filesize($entry)."</td><td>".zip_entry_compressedsize($entry)."</td></tr>";
}
$html .="</table>";
echo $html;
}
zip_close($zip);

1、该版本可能就比较复杂
function ezip($file,$path){
$zip = zip_open($file);
if($zip == true){
while ($entry = zip_read($zip)) {
$name = zip_entry_name($entry);
$rel_path = is_dir($name) ? $name : dirname($name);
$basePath = $path."/".$rel_path;
mkdirs($basePath);
if(zip_entry_open($zip, $entry)){
$fw = @fopen($path."/".$name, "w+");
$content = zip_entry_read($entry);
@fwrite($fw, $content);
@fclose($fw);
}
zip_entry_close($entry);
}
}
zip_close($zip);
}
function mkdirs($dir){
return is_dir($dir) or mkdirs(dirname($dir)) and @mkdir($dir,0777);
}
ezip("demo.zip",'h');
