Home PHP Zip zip_entry_filesize() PHP zip_entry_filesize() Function Definition In PHP, zip_entry_filesize() returns the original, uncompressed size of a ZIP entry in bytes.
It is deprecated as of PHP 8.0. With ZipArchive, call statName() or statIndex() and read the size key.
Syntax Call zip_entry_filesize() with the values you need. Start with this line.
// Deprecated (PHP 8.0+)
$bytes = zip_entry_filesize($entry);
// Modern equivalent
$stat = $zip->statName('hello.txt');
$bytes = $stat['size']; Call What it does zip_entry_filesize($entry)Deprecated: returns the uncompressed size of the current entry. @zip_entry_filesize($entry)Deprecated: the @ operator hides the E_DEPRECATED notice only. $zip->statName('hello.txt')['size']Modern ZipArchive: reads the uncompressed size from the stat array.
zip_entry_filesize() is deprecated in PHP 8.0. ZipArchive::statName() returns false when the entry does not exist, so check the result before using the size key.
Library declarations zip_entry_filesize(resource $zip_entry): int|false Parameters Parameter Description zip_entry Required. A directory entry resource returned by zip_read(). In ZipArchive you use the entry name or index instead.
Return Value Return Value Description int The uncompressed size of the entry in bytes. false The size could not be read.
PHP Examples 1. Read size From statName() 2. Empty and Missing Entries 3. Total Uncompressed Size Example 1 — Read size From statName() Create a small archive and print the uncompressed size of one entry.
<?php
// Legacy (deprecated since PHP 8.0):
// $bytes = zip_entry_filesize($entry);
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'codetofun_' . uniqid() . '.zip';
$zip = new ZipArchive();
$zip->open($path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFromString('hello.txt', "Hello zip\n");
$zip->close();
$zip = new ZipArchive();
$zip->open($path);
$stat = $zip->statName('hello.txt');
echo 'hello.txt: ', $stat['size'], ' bytes', PHP_EOL;
$zip->close();
unlink($path); How It Works Create an archive with hello. txt (nine letters plus a newline).Reopen the archive for reading. Call statName() and take the size key. Print the byte count and delete the temp file. Example 2 — Empty and Missing Entries An empty entry has size 0, while a missing entry makes statName() return false.
<?php
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'codetofun_' . uniqid() . '.zip';
$zip = new ZipArchive();
$zip->open($path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFromString('empty.txt', '');
$zip->addFromString('one.txt', 'x');
$zip->close();
$zip = new ZipArchive();
$zip->open($path);
foreach (['empty.txt', 'one.txt', 'missing.txt'] as $name) {
$stat = $zip->statName($name);
if ($stat === false) {
echo $name, ': not found', PHP_EOL;
} else {
echo $name, ': ', $stat['size'], ' bytes', PHP_EOL;
}
}
$zip->close();
unlink($path); empty.txt: 0 bytes
one.txt: 1 bytes
missing.txt: not found How It Works Add an empty entry and a one-letter entry. Reopen the archive and loop over three names. Treat a false result from statName() as not found. Print the size for entries that exist, then unlink the archive. Frequently Asked Questions Is zip_entry_filesize() deprecated? Yes. The procedural zip_* functions are deprecated as of PHP 8.0. Use ZipArchive::statName() or statIndex() and read size.
What is the difference between size and comp_size? size is the original uncompressed length. comp_size is how many bytes the entry takes inside the archive.
What does statName() return for a missing file? It returns false. Always check for false before reading the size key.
Why check the size before extracting? A malicious archive can claim a very large uncompressed size. Checking size first lets you refuse risky files.
Can an entry have a size of zero? Yes. Empty files and folders have size 0. That is a valid result, not an error.
Next: zip_entry_name() zip_entry_name() returns the name of a ZIP entry, including any folder path inside the arc.
zip_entry_name() tutorial → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion