Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check file sizes of content inside ZIP archive

Tags:

php

zip

filesize

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

like image 677
aborted Avatar asked Aug 19 '12 12:08

aborted


1 Answers

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.

<?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
like image 56
Shankar Narayana Damodaran Avatar answered Oct 22 '22 08:10

Shankar Narayana Damodaran