PHP zip_entry_filesize() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Zip

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.

PHP
// Deprecated (PHP 8.0+)
$bytes = zip_entry_filesize($entry);

// Modern equivalent
$stat = $zip->statName('hello.txt');
$bytes = $stat['size'];
CallWhat 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
PHP
zip_entry_filesize(resource $zip_entry): int|false

Parameters

ParameterDescription
zip_entryRequired. A directory entry resource returned by zip_read(). In ZipArchive you use the entry name or index instead.

Return Value

Return ValueDescription
intThe uncompressed size of the entry in bytes.
falseThe size could not be read.

PHP Examples

Example 1 — Read size From statName()

Create a small archive and print the uncompressed size of one entry.

PHP
<?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

  1. Create an archive with hello. txt (nine letters plus a newline).
  2. Reopen the archive for reading.
  3. Call statName() and take the size key.
  4. 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
<?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);

How It Works

  1. Add an empty entry and a one-letter entry.
  2. Reopen the archive and loop over three names.
  3. Treat a false result from statName() as not found.
  4. Print the size for entries that exist, then unlink the archive.

Example 3 — Total Uncompressed Size

Add up the size of every entry, like a safety check before extraction.

PHP
<?php
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'codetofun_' . uniqid() . '.zip';

$zip = new ZipArchive();
$zip->open($path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFromString('a.txt', 'AAAA');
$zip->addFromString('b.txt', 'BBBBBB');
$zip->addFromString('c.txt', 'CCCCCCCC');
$zip->close();

$zip = new ZipArchive();
$zip->open($path);
$total = 0;
for ($i = 0; $i < $zip->numFiles; $i++) {
    $stat = $zip->statIndex($i);
    $total += $stat['size'];
    echo $stat['name'], ': ', $stat['size'], PHP_EOL;
}
echo 'Total: ', $total, ' bytes', PHP_EOL;
$zip->close();

unlink($path);

How It Works

  1. Create three entries with 4, 6, and 8 characters.
  2. Reopen the archive and start a total at zero.
  3. Loop with statIndex(), add each size, and print each entry.
  4. Print the total and delete the temp archive.

Frequently Asked Questions

Yes. The procedural zip_* functions are deprecated as of PHP 8.0. Use ZipArchive::statName() or statIndex() and read size.
size is the original uncompressed length. comp_size is how many bytes the entry takes inside the archive.
It returns false. Always check for false before reading the size key.
A malicious archive can claim a very large uncompressed size. Checking size first lets you refuse risky files.
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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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