BBM Tutor
BBM Tutor

PHP Zip - zip_entry_compressionmethod()

Description & Uses of PHP zip_entry_compressionmethod()

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

Simple Example - PHP zip_entry_compressionmethod(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_Type = zip_entry_compressionmethod($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Type . ") ");
zip_close($ZipHandler);
?>

PHP Output Screen

File Name: Invoice.txt (deflated)

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_compressionmethod(Resource $zip_entry);
?>

Parameter & Return Type

Description

Resource $ZipHandler
Specifies the Resource Handler of an Zip Archive Entry. (*Required)
Return String $file_Type
Returns the Compressio Method of a File or Directory of the Zip Archive Entry only if Success otherwise a PHP Warning.

What is PHP zip_entry_compressionmethod() ?

  • It returns an Compression Method of a File or Directory of the specified Zip Archive entry only if Success otherwise a PHP Warning.
  • There are seven types of Compression Methods. They are
    • uncompressed
    • Shrunk
    • Reduced (1 to 4)
    • Imploded
    • Tokenizing (reserviert)
    • Deflate
    • BZIP2
  • The default Compression Method of the Zip Archive (Refer Example #1 & #2)
    • File - Deflated
    • Directory - Stored (uncompressed)
    • Compressed Directory (.zip, .rar, .bz2, etc.,) - Stored (uncompressed)
  • 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 #3)
  • Reading of an Invalid or an Empty Resource Handler leads to PHP Warning (Refer Example #3).
    It can be avoided by a special Error Handling Technique (Refer Example #4)
BBM Invoice

Example #1 - PHP zip_entry_compressionmethod(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);
/* Compression Method of a Zip Archive Entry in a Stream */
$file_Type = zip_entry_compressionmethod($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Type . ") ");
echo "<br>" ;
}
zip_close($ZipHandler);
} else {
echo("Failed to Open. Error Code: " . $ZipHandler);
}
?>

PHP Output Screen

File Name: YGen/YGen.jpg (deflated)
File Name: YGen/YGen.pdf (deflated)
File Name: YGen/YGen.txt (deflated)
File Name: BBMINFO.jpg (deflated)
File Name: Invoice/Features/ (stored)
File Name: Invoice/Features/KeyFeatures.rtf (deflated)
File Name: Invoice/Invoice.txt (deflated)

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_compressionmethod(Resource $zipEntry);

PHP Input Screen

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

PHP Output Screen

File Name: EmptyBox.zip (stored)

bbminfo Demo Zip Archive File: EmptyBoxOut.zip

  • It contains 1 File:
    • EmptyBox.zip
  • Download the Demo Zip Archive File: EmptyBoxOut.zip for your tutorial reference purpose.
BBM Invoice

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

PHP Input Screen

<?php
$ZipHandler = zip_open("./EmptyBox.zip");
$zipEntry = zip_read($ZipHandler);
$file_Name = zip_entry_name($zipEntry);
/* Compression Method of a Zip Archive Entry in a Stream */
$file_Type = zip_entry_compressionmethod($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Type . ") ");
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_compressionmethod() 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_compressionmethod(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);
/* Compression Method of a Zip Archive Entry in a Stream */
$file_Type = zip_entry_compressionmethod($zipEntry);
echo("File Name: " . $file_Name . " (" . $file_Type . ") ");
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.