PHP zip_entry_filesize - Syntax
zip_entry_filesize(resource $entry): int|false
zip_entry_filesize() reports the uncompressed size of a ZIP entry in bytes. PHP deprecated this procedural function in 8.0. For new code, use ZipArchive::statIndex().
zip_entry_filesize()
Use ZipArchive to read entries by name in modern PHP.
To run the examples, save bbminfo.zip and bbminfo-nested-folder.zip beside your script and run it from that directory.
zip_entry_filesize(resource $entry): int|false
| Arguments | resource $entry |
|---|---|
| Return value | The uncompressed byte count, or false on failure. |
A desktop importer must allow space for materials after extraction. The cataloguer reads the uncompressed byte count for each member before unpacking it.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo.zip");
if(is_resource($zipHandler)) {
while($zipEntry = zip_read($zipHandler)) {
// Get the file name
$fileName = zip_entry_name($zipEntry);
// Get the original file size in bytes (i.e. un-compressed file size)
$fileSize = zip_entry_filesize($zipEntry);
echo("File: " . $fileName . " (" . $fileSize . " bytes)");
echo "\n" ;
}
zip_close($zipHandler);
} else {
echo("Failed to Open. Error Code: " . $zipHandler);
}
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
File: bbminfo/readme.txt (67 bytes)
A teacher organizes slides and images in nested folders inside a course ZIP. Match the full archive path to the uncompressed size so similarly named files are distinguishable.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo-nested-folder.zip");
if(is_resource($zipHandler)) {
while($zipEntry = zip_read($zipHandler)) {
// Get the file name
$resourceName = zip_entry_name($zipEntry);
// Get the original file size in bytes
$fileSize = zip_entry_filesize($zipEntry);
if(substr($resourceName, -1) == "/") {
echo("Directory: " . $resourceName);
} else {
echo("File: " . $resourceName . " (" . $fileSize . " bytes)");
}
echo "\n" ;
}
zip_close($zipHandler);
} else {
echo("Failed to Open. Error Code: " . $zipHandler);
}
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
Directory: bbminfo-nested-folder/img/ File: bbminfo-nested-folder/img/bbminfo_icon.png (7532 bytes) File: bbminfo-nested-folder/readme.txt (59 bytes) File: bbminfo-nested-folder/tutorial-doc.pdf (32540 bytes)
A teacher saves the bytes for the word alto in an uncompressed archive member. Read the stored byte count for the member. The archive uses the store method, which leaves the member data uncompressed.
The archive contains one stored member. Its entry metadata and contents can be inspected independently.
Reference: PHP manual — zip_entry_filesize()