BBM Tutor
BBM Tutor

PHP Zip - zip_entry_compressedsize()

Description & Uses of PHP zip_entry_compressedsize()

The PHP zip_entry_compressedsize() function is used to retrieve the Compressed size of a File or Directory from a specified Zip Archive Entry. It returns the value in bytes only if Success otherwise a PHP Warning.

Simple Example - PHP zip_entry_compressedsize(Resource $zipEntry);

PHP Input Screen

<?php
$ZipHandler = zip_open("./Invoice.zip");
$zipEntry = zip_read($ZipHandler);
$file_Name = zip_entry_name($zipEntry);
/* Compressed File Size of a Zip Archive Entry in a Stream */
$file_Size = zip_entry_compressedsize($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Size . " Byte) ");
zip_close($ZipHandler);
?>

PHP Output Screen

File Name: Invoice.txt (202 Byte)

bbminfo Demo Zip Archive File: Invoice.zip

  • It contains the following file
    • Invoice.txt
  • Download the Demo Zip Archive File: Invoice.zip for your tutorial reference purpose.
BBM Invoice

Simple PHP Syntax

<?php
zip_entry_compressedsize(Resource $zipEntry);
?>

Parameter & Return Type

Description

Resource $ZipHandler
Specifies the Resource Handler of an Zip Archive Entry. (*Required)
Return Int $file_Size
Returns the Compressed Size of a File or Directory of the Zip Archive Entry only if Success otherwise a PHP Warning.

What is PHP zip_entry_compressedsize() ?

  • It returns an Compressed Size of a File or Directory of the specified Zip Archive entry only if Success otherwise a PHP Warning.
  • Common Error Codes in PHP Zip Functions
    • Invalide Zip Archive - Returns an ER_OPEN (Error Code: 11)
    • Empty Zip Archive - Returns an ER_NOZIP (Error Code: 19)
  • The Zip Archive must contain atleast a file or a directory otherwise it produce a PHP Warning (Refer Example #2)
  • Reading of an Invalid or an Empty Resource Handler leads to PHP Warning (Refer Example #2).
    It can be avoided by a special Error Handling Technique (Refer Example #3)
BBM Invoice

Example #1 - PHP zip_entry_compressedsize(Resource $zipEntry);

PHP Input Screen

<?php
$ZipHandler = zip_open("./BBMINFO.zip");
if(is_resource($ZipHandler)) {
while($zipEntry = zip_read($ZipHandler)) {
$file_Name = zip_entry_name($zipEntry);
/* Compressed File Size of a Zip Archive Entry in a Stream */
$file_Size = zip_entry_compressedsize($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Size . " Byte) ");
echo "<br>" ;
}
zip_close($ZipHandler);
} else {
echo("Failed to Open. Error Code: " . $ZipHandler);
}
?>

PHP Output Screen

File Name: YGen/YGen.jpg (43651 Byte)
File Name: YGen/YGen.pdf (225679 Byte)
File Name: YGen/YGen.txt (453 Byte)
File Name: BBMINFO.jpg (161250 Byte)
File Name: Invoice/Features/ (0 Byte)
File Name: Invoice/Features/KeyFeatures.rtf (362 Byte)
File Name: Invoice/Invoice.txt (202 Byte)

bbminfo Demo Zip Archive File: BBMINFO.zip

  • It contains 2 Directories & 1 File, they are
    • Directory : YGen contains 3 Files, they are
      • YGen.jpg
      • YGen.pdf
      • YGen.txt
    • Directory : Invoice contains 1 Sub Directory & 1 File
      • Directory : Features contains 1 File
        • KeyFeatures.rtf
      • Invoice.txt
    • BBMINFO.jpg
  • Download the Demo Zip Archive File: BBMINFO.zip for your tutorial reference purpose.
BBM Invoice

Example #2 - PHP zip_entry_compressedsize(Resource $zipEntry);

PHP Input Screen

<?php
$ZipHandler = zip_open("./EmptyBox.zip");
$zipEntry = zip_read($ZipHandler);
$file_Name = zip_entry_name($zipEntry);
/* Compressed File Size of a Zip Archive Entry in a Stream */
$file_Size = zip_entry_compressedsize($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Size . " Byte) ");
zip_close($ZipHandler);
?>

PHP Output Screen

PHP Warning: zip_read() expects parameter 1 to be resource, integer given in /home1/bbminfoc/public_html/Tutor/error.php on line 3
PHP Warning: zip_entry_name() expects parameter 1 to be resource, integer given in /home1/bbminfoc/public_html/Tutor/error.php on line 4
PHP Warning: zip_entry_compressedsize() expects parameter 1 to be resource, null given in /home1/bbminfoc/public_html/Tutor/super.php on line 6
PHP Warning: zip_close() expects parameter 1 to be resource, integer given in /home1/bbminfoc/public_html/Tutor/error.php on line 8

bbminfo Demo Zip Archive File: EmptyBox.zip

  • It contains 0 Files (No Files are there in the Zip Archive)
  • Download the Demo Zip Archive File: EmptyBox.zip for your tutorial reference purpose.
BBM Invoice

Example #3 - PHP zip_entry_compressedsize(Resource $zipEntry);

PHP Input Screen

<?php
$ZipHandler = zip_open("./EmptyBox.zip");
if(is_resource($ZipHandler)) {
while($zipEntry = zip_read($ZipHandler)) {
$file_Name = zip_entry_name($zipEntry);
/* Compressed File Size of a Zip Archive Entry in a Stream */
$file_Size = zip_entry_compressedsize($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Size . " Byte) ");
echo "<br>" ;
}
zip_close($ZipHandler);
} else {
echo("Failed to Open. Error Code: " . $ZipHandler);
}
?>

PHP Output Screen

Failed to Open. Error Code: 19

BBM Invoice
 
Disclaimer: Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.