Example 1 — Read comp_size From statName()
Store one entry without compression so the numbers are always the same, then read size and comp_size.
<?php
// Legacy (deprecated since PHP 8.0):
// $bytes = zip_entry_compressedsize($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->setCompressionName('hello.txt', ZipArchive::CM_STORE);
$zip->close();
$zip = new ZipArchive();
$zip->open($path);
$stat = $zip->statName('hello.txt');
echo 'size: ', $stat['size'], PHP_EOL;
echo 'comp_size: ', $stat['comp_size'], PHP_EOL;
$zip->close();
unlink($path); How It Works
- Create an archive and add hello. txt.
- Force the STORE method so no compression is applied.
- Reopen the archive and call statName() on hello. txt.
- Print size and comp_size, then delete the temp file.

