PHP | zip_entry_compressionmethod() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The zip_entry_compressionmethod() function is an inbuilt function in PHP which is used to return the compression method of a file or a directory from a zip archive entry. The zip entry resource which has to be read is sent as a parameter to the zip_entry_compressionmethod() function and it returns the compression method on Success. Compression methods are of seven types which are as follows : uncompressed Shrunk Deflate Reduced (1 to 4) Tokenizing Imploded BZIP2 The default compression method of the zip archive file is deflated. Syntax: string zip_entry_compressionmethod( $zip_entry ) Parameters: This function accepts single parameter $zip_entry. It is a mandatory parameter which specifies the zip entry resource. Return Value: It returns the compression method of a file or directory of the specified zip archive entry on success otherwise a PHP Warning. Errors And Exceptions The zip_entry_compressionmethod() returns the compressed method of a file or a directory only on Success otherwise it returns a PHP warning. The zip_entry_compressionmethod() function returns an ER_OPEN error if the zip archive is invalid. The zip_entry_compressionmethod() function returns an ER_NOZIP error if the zip archive is empty. Below programs illustrate the zip_entry_compressionmethod() function in PHP: Program 1: Suppose a zip file article.zip contains the following file: content.xlsx php <?php // Opening a zip archive $zip_handle = zip_open("C:/xampp/htdocs/article.zip"); // Reading a zip archive $zip_entry = zip_read($zip_handle); $file = zip_entry_name($zip_entry); // Checking the compression method $comp_type = zip_entry_compressionmethod($zip_entry); echo("File Name: " . $file . "=>" . $comp_type); // Closing the zip archive zip_close($zip_handle); ?> Output: File Name: article/content.xlsx => deflated Program 2: Suppose a zip file article.zip contains the following file: art.zip content.xlsx gfg.pdf image.jpeg php <?php // Opening a zip archive $zip_handle = zip_open("C:/xampp/htdocs/article.zip"); if(is_resource($zip_handle)) { // Reading a zip archive while($zip_entry = zip_read($zip_handle)) { $file = zip_entry_name($zip_entry); // Checking the compression method $comp_type = zip_entry_compressionmethod($zip_entry); echo("File Name: " . $file . " => " . $comp_type . "<br>"); } // Closing the zip archive zip_close($zip_handle); } else echo("Zip archive cannot be opened."); ?> Output: File Name: article/art.zip => stored File Name: article/content.xlsx => deflated File Name: article/gfg.pdf => deflated File Name: article/image.jpeg => deflated Related Articles: PHP | zip_entry_compressedsize() Function PHP | zip_entry_close() Function PHP | zip_close( ) Function Reference : https://www.php.net/manual/en/function.zip-entry-compressionmethod.php Comment More infoAdvertise with us Next Article PHP | zip_entry_read() Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-file-handling PHP-function +1 More Practice Tags : Misc Similar Reads PHP | zip_entry_compressedsize() Function The zip_entry_compressedsize() function is an inbuilt function in PHP which is used to return the size of the compressed file in zip archive entry. It can be used to retrieve the compressed size of a directory entry. The zip entry resource which has to be read is sent as a parameter to the zip_entry 2 min read PHP | zip_entry_close() Function The zip_entry_close() function is an inbuilt function in PHP which is used to close a zip archive opened by the zip_entry_open() function. The zip_entry_close() causes the stream to be closed and the connection to the corresponding Zip Archive Entry which may be a file or a directory within the Zip 3 min read PHP | zip_close( ) Function The zip_close() function is an inbuilt function in PHP which is used to close a zip archive file opened by the zip_open() function. The zip_close() causes the stream to be closed and the connection to the corresponding Zip Archive to be broken. The zip resource which has been opened by the zip_open( 2 min read PHP | zip_entry_open() Function The zip_entry_open() function is an inbuilt function in PHP which is used to open a zip entry archive for reading. Opening a file or a directory in a zip archive with the zip_entry_open function creates a new stream and establishes a connection between the stream and a file or a directory in a Zip A 3 min read PHP | zip_entry_read() Function The zip_entry_read() function is an inbuilt function in PHP which is used to read the contents from an opened zip archive entry. The zip entry is being read and the number of bytes to be returned can be sent as a parameter to the zip_entry_read() function and it returns the content of the specified 3 min read PHP | zip_entry_name() Function The zip_entry_name() function is an inbuilt function in PHP which is used to return the name of a zip archive entry. The zip entry resource is to be read and sent as a parameter to the zip_entry_name() function and it returns the name of the zip entry archive on Success. Syntax: string zip_entry_nam 2 min read Like