Friday, September 5, 2025
HomeLanguagesPHP | zip_entry_compressionmethod() Function

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 :

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS