【问题标题】:php ZipArchive count number of files inside archivephp ZipArchive 计数存档中的文件数
【发布时间】:2013-06-26 14:46:50
【问题描述】:

我有这个代码:

$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;
                }
            }

我想在显示列表之前显示存档中的文件数。我该怎么做?

【问题讨论】:

标签: php count zip


【解决方案1】:

您已经在for 循环中找到了答案:

echo "Number of files inside Zip = ".$za->numFiles;

http://php.net/manual/en/class.ziparchive.php

【讨论】:

    【解决方案2】:

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-03
      • 2016-07-17
      • 2014-03-28
      • 2020-09-05
      • 2023-03-03
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多