PHP zip_entry_compressionmethod - Syntax
zip_entry_compressionmethod(resource $ziphandler): string
The PHP zip_entry_compressionmethod() function is used to retrieve the compression method type of a file or directory from a specified Zip Archive Entry and it returns the compression method type only if success otherwise a PHP warning.
zip_entry_compressionmethod(resource $ziphandler): string
resource $zipHandler |
Specifies the Resource Handler of a zip archive file (*Required) |
---|---|
Return string $compressionType |
Returns the compression method type of a file or directory of the Zip archive entry only if success otherwise it will throw a PHP Warning. |
The Compression method types are as follows
Open a zip archieve and print the compressed method name of all entries.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo-nested-folder.zip");
if(is_resource($zipHandler)) {
while($zipEntry = zip_read($zipHandler)) {
// Get the file name
$resourceName = zip_entry_name($zipEntry);
// Get the compressed file size in bytes
$fileType = zip_entry_compressionmethod($zipEntry);
if(substr($resourceName, -1) == "/") {
echo("Directory: " . $resourceName . " (" . $fileType . ")");
} else {
echo("File: " . $resourceName . " (" . $fileType . ")");
}
echo "\n" ;
}
zip_close($zipHandler);
} else {
echo("Failed to Open. Error Code: " . $zipHandler);
}
}
}
$obj = new ZipExample();
$obj->processZipArchieve();