Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
zip_entry_compressed_size() function in PHP
The zip_entry_compressed_size() function returns the compressed file size of a zip archive entry. This function is part of PHP's legacy ZIP extension and is used to retrieve the size of compressed files within a ZIP archive.
Syntax
zip_entry_compressed_size(zip_entry)
Parameters
zip_entry − The zip entry resource obtained from
zip_read(). Required.
Return Value
Returns the compressed file size in bytes as an integer, or FALSE on failure.
Example
The following example demonstrates how to get the compressed size of files in a ZIP archive ?
<?php
$zip = zip_open("sample.zip");
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$filename = zip_entry_name($zip_entry);
$compressed_size = zip_entry_compressedsize($zip_entry);
echo "File: " . $filename . " - Compressed Size: " . $compressed_size . " bytes<br />";
}
zip_close($zip);
} else {
echo "Failed to open ZIP file";
}
?>
File: document.txt - Compressed Size: 90 bytes File: image.jpg - Compressed Size: 12 bytes File: data.csv - Compressed Size: 67 bytes
Key Points
- This function is part of the deprecated ZIP extension (removed in PHP 8.0)
- Use
ZipArchiveclass for modern ZIP handling in PHP - The compressed size is usually smaller than the original file size due to compression
- Always check if the ZIP file opens successfully before processing entries
Conclusion
The zip_entry_compressed_size() function provides the compressed size of ZIP archive entries. For new projects, consider using the modern ZipArchive class instead of these legacy functions.
Advertisements
