我有这个代码:
$za = new ZipArchive();
$za->open($downloadlink);
echo "Number of files inside Zip = Unknown";
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$tounes = array( basename( $stat['name'] ) . PHP_EOL );
foreach($tounes as $toune) {
echo $toune;
}
}
在显示列表之前,我想显示存档中的文件数。我该怎么做?
您的for
循环中已经有了答案:
echo "Number of files inside Zip = ".$za->numFiles;
http://php.net/manual/en/class.ziparchive.php
numFiles将统计档案中的所有文件和文件夹。如果您仅需要文件数,请通过检查大小来计算文件夹数(文件夹大小为0):
$zip = new ZipArchive();
$zip->open('archive.zip');
$result_stats = array();
for ($i = 0; $i < $zip->numFiles; $i++)
{
$stat = $zip->statIndex($i);
if ($stat['size'])
$result_stats[] = $stat;
}
echo count($result_stats);