W3docs

zip_entry_filesize()

The zip_entry_filesize() function is a built-in function in PHP that is used to get the uncompressed size of a file in a zip archive. The uncompressed size is

The zip_entry_filesize() function was a built-in PHP function that returned the uncompressed (original) size, in bytes, of a single file inside a zip archive. It worked together with the old procedural zip API (zip_open(), zip_read(), and zip_entry_open()).

Warning

zip_entry_filesize() was deprecated in PHP 8.0 and removed in PHP 8.1. It does not exist in modern PHP. New code should use the ZipArchive class instead — this page shows the equivalent, supported approach.

What "uncompressed size" means

A zip archive stores two sizes for every entry:

  • Uncompressed size — how big the file is once extracted (what zip_entry_filesize() reported, and what ZipArchive::statName() exposes as size).
  • Compressed size — how many bytes the entry actually occupies inside the archive after compression. In the procedural API this was zip_entry_compressedsize(); with ZipArchive it is the comp_size field.

Knowing the uncompressed size up front is useful for showing download sizes to users, deciding whether you have enough disk space to extract, or validating an upload before unpacking it.

Legacy syntax

For reference, the original signature was:

int zip_entry_filesize(resource $zip_entry)

Where $zip_entry is a zip-entry handle returned by zip_read(). It returned the entry's uncompressed size in bytes. Because the function no longer exists, do not use this in new code.

The modern replacement: ZipArchive::statName()

The supported way to read an entry's uncompressed size is ZipArchive::statName(), which returns an associative array of metadata (or false if the entry is missing). The size key holds the uncompressed size.

$zip = new ZipArchive();
if ($zip->open('example.zip') === true) {
    $stat = $zip->statName('file.txt');
    if ($stat !== false) {
        echo "The uncompressed size of the file is: " . $stat['size'] . " bytes.";
    } else {
        echo "File not found in archive.";
    }
    $zip->close();
} else {
    echo "Failed to open archive.";
}

statName() looks an entry up by its path inside the archive. If you only have an index (for example while looping with numFiles), use statIndex() instead — it returns the same array shape.

Comparing compressed and uncompressed size

Because the stat array carries both numbers, you can report the compression ratio in one pass — no separate calls like the old zip_entry_filesize() / zip_entry_compressedsize() pair:

$zip = new ZipArchive();
if ($zip->open('example.zip') === true) {
    for ($i = 0; $i < $zip->numFiles; $i++) {
        $stat = $zip->statIndex($i);
        $saved = $stat['size'] > 0
            ? round(100 * (1 - $stat['comp_size'] / $stat['size']))
            : 0;
        echo "{$stat['name']}: {$stat['size']} bytes -> {$stat['comp_size']} bytes ({$saved}% saved)\n";
    }
    $zip->close();
} else {
    echo "Failed to open archive.";
}

Common gotchas

  • Check the return value. open() returns true on success or an error code (an integer) on failure, so compare with === true, not a loose truthy check. statName() returns false for a missing entry.
  • size is the uncompressed value. A common mistake is to assume it's the on-disk size inside the zip — that's comp_size.
  • Directories are entries too. When looping with statIndex(), directory entries appear with a trailing / and a size of 0.

Conclusion

zip_entry_filesize() was removed in PHP 8.1, so it should not appear in new code. Its job — reading the uncompressed size of an entry — is now handled by ZipArchive::statName() (or statIndex()), whose size field gives the same value while also exposing comp_size for the compressed size. See the ZipArchive overview and filesize() for related file-size helpers.

Practice

Practice
What is the role of the zip_entry_filesize() function in PHP?
What is the role of the zip_entry_filesize() function in PHP?
Was this page helpful?