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 function in PHP that was used to get the uncompressed size of a file in a zip archive. Important: This function was deprecated in PHP 8.0 and removed in PHP 8.1. It is no longer available in modern PHP versions. For current compatibility, use the ZipArchive class instead.

Syntax

The syntax of the zip_entry_filesize() function is as follows:

syntax of the zip_entry_filesize() function in PHP

int zip_entry_filesize(resource $zip_entry)

Where $zip_entry is the zip_entry handle for the file in the zip archive.

Usage Examples

Let's take a look at a practical example of using the modern ZipArchive class in PHP, which replaces the obsolete zip_open and zip_read workflow.

Example: Getting the Uncompressed Size of a File in a Zip Archive

Suppose you have a zip archive and want to get the uncompressed size of a file in it. You can use the ZipArchive class with proper error handling and the statName method, like this:

Getting the Uncompressed Size of a File in a Zip Archive in PHP

$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.";
}

This code creates a ZipArchive instance and opens the archive file example.zip. It then uses statName() to retrieve metadata for a specific file, including its uncompressed size. The example includes error handling to verify that the archive opened successfully and that the target file exists, and it properly closes the archive to prevent resource leaks.

Conclusion

In this article, we've discussed the zip_entry_filesize() function and noted that it was deprecated in PHP 8.0 and removed in PHP 8.1. We've explained what the function did, its syntax, and provided a modern, error-safe example using the ZipArchive class and statName() to get file sizes in current PHP versions. By using ZipArchive in your PHP applications, you can reliably get the uncompressed size of a file in a zip archive and use that information as needed.

Practice

Practice

What is the role of the zip_entry_filesize() function in PHP?