简体   繁体   English

检查ZIP存档内的文件大小

[英]Check file sizes of content inside ZIP archive

I need to open a ZIP archive, check the file size of each file inside the archive and return an array with the numeric values (sizes). 我需要打开一个ZIP存档,检查存档中每个文件的文件大小,并返回一个包含数值(大小)的数组。 I don't want the archive to be extracted to check the file sizes, possibly. 我不希望提取存档以检查文件大小。

I tried a lot myself, but no ZIP function seems to have a feature like that and I couldn't think of any combination to write the function myself. 我自己尝试了很多,但没有ZIP功能似乎有这样的功能,我想不出任何组合自己编写功能。

I know this question is pretty old. 我知道这个问题很老了。 I hope this answer could help someone. 我希望这个答案可以帮助某人。
The following code cycles up all the files inside the test2.zip file and prints its name and the sizes in bytes. 以下代码循环test2.zip文件中的所有文件,并以字节为单位打印其名称和大小。

<?php
$zip = new ZipArchive;
$res = $zip->open('test2.zip');
if ($res) {
    $i=0;
    while(!empty($zip->statIndex($i)['name']))
    {
       echo "Filename: ".$zip->statIndex($i)['name']." | Size: ".$zip->statIndex($i)['size']." bytes<br>";
       $i++;
    }
}
?>

OUTPUT : 输出:

Filename: main.php | Size: 44 bytes
Filename: test.php | Size: 385 bytes
Filename: test2.json | Size: 35 bytes
Filename: Token.txt | Size: 5 bytes
Filename: trans.png | Size: 95442 bytes
Filename: url_xml.xml | Size: 399 bytes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM