PHP zip_entry_compressedsize - Syntax
zip_entry_compressedsize(resource $entry): int|false
zip_entry_compressedsize() reports the compressed size of a ZIP entry in bytes. PHP deprecated this procedural function in 8.0. For new code, use ZipArchive::statIndex().
zip_entry_compressedsize()
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_compressedsize(resource $entry): int|false
| Arguments | resource $entry |
|---|---|
| Return value | The compressed byte count, or false on failure. |
A course editor records how many compressed bytes each item occupies inside a handout bundle. Read the stored byte count per entry before planning the download.
<?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 compressed file size in bytes
$fileSize = zip_entry_compressedsize($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 (59 bytes)
A school archives material in nested folders. Walk the entries in order so the inventory associates each stored byte count with the correct member.
<?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 compressed file size in bytes
$fileSize = zip_entry_compressedsize($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_compressedsize()