[英]php ZipArchive count number of files inside archive
我有這個代碼:
$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;
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.