Open In App

PHP | zip_entry_compressionmethod() Function

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 :



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

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
  
// 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
  
// 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:

Reference : http://php.net/manual/en/function.zip-entry-compressionmethod.php


Article Tags :