在PHP中可以检查Zip文件的内容而无需先提取其内容? [英] In PHP is it possible to inspect content of a Zip file without extracting its content first?

查看:92
本文介绍了在PHP中可以检查Zip文件的内容而无需先提取其内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过PHP中的ZipArchive类,它使您可以读取zip文件.但我想知道是否有一种方法可以在不首先提取文件的情况下遍历其内容

I have seen the ZipArchive class in PHP which lets you read zip files. But I'm wondering if there is a way to iterate though its content without extracting the file first

推荐答案

作为对 http://www.php.net的评论而发现/ziparchive :

以下代码可用于获取以下文件中所有文件名的列表: 一个zip文件.

The following code can be used to get a list of all the file names in a zip file.

<?php
$za = new ZipArchive(); 

$za->open('theZip.zip'); 

for( $i = 0; $i < $za->numFiles; $i++ ){ 
    $stat = $za->statIndex( $i ); 
    print_r( basename( $stat['name'] ) . PHP_EOL ); 
}
?>

这篇关于在PHP中可以检查Zip文件的内容而无需先提取其内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆