PHP zip_entry_compressionmethod - Syntax
zip_entry_compressionmethod(resource $entry): string|false
zip_entry_compressionmethod() identifies the compression method used for an entry. PHP deprecated this procedural function in 8.0. For new code, use ZipArchive::statIndex().
zip_entry_compressionmethod()
Use ZipArchive to read entries by name in modern PHP.
To run the examples, save bbminfo.zip and bbminfo-nested-folder.zip beside your script and run it from that directory.
zip_entry_compressionmethod(resource $entry): string|false
| Arguments | resource $entry |
|---|---|
| Return value | A method name, or false on failure. ZipArchive::statIndex exposes a numeric comp_method field instead. |
The Compression method types are as follows
A librarian is comparing how a handout archive stores its members. Read each entry’s compression method so the catalogue can distinguish stored files from compressed ones.
<?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();
File: bbminfo-nested-folder/img/ (stored) File: bbminfo-nested-folder/img/bbminfo_icon.png (deflated) File: bbminfo-nested-folder/readme.txt (deflated) File: bbminfo-nested-folder/tutorial-doc.pdf (deflated)
A teacher saves the bytes for the word alto in an uncompressed archive member. Inspect the compression method recorded for the member. Which method name should the catalog display?
The archive contains one stored member. Its entry metadata and contents can be inspected independently.
A tutor saves the bytes for glaze in a second uncompressed archive member. Inspect the compression method recorded for the member. Which method name should the catalog display?
The archive contains one stored member. Its entry metadata and contents can be inspected independently.
Reference: PHP manual — zip_entry_compressionmethod()