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
$zip_handle = zip_open("C:/xampp/htdocs/article.zip");
$zip_entry = zip_read($zip_handle);
$file = zip_entry_name($zip_entry);
$comp_type = zip_entry_compressionmethod($zip_entry);
echo("File Name: " . $file . "=>" . $comp_type);
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
$zip_handle = zip_open("C:/xampp/htdocs/article.zip");
if(is_resource($zip_handle))
{
while($zip_entry = zip_read($zip_handle))
{
$file = zip_entry_name($zip_entry);
$comp_type = zip_entry_compressionmethod($zip_entry);
echo("File Name: " . $file . " => " . $comp_type . "<br>");
}
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