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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With