PHP zip_entry_open - Syntax
zip_entry_open(resource $zip, resource $entry, string $mode = "rb"): bool
zip_entry_open() opens an archive entry for reading. PHP deprecated this procedural function in 8.0. For new code, use ZipArchive::getStream().
zip_entry_open()
Use ZipArchive to read entries by name in modern PHP.
To run the examples, save bbminfo.zip beside your script and run it from that directory.
zip_entry_open(resource $zip, resource $entry, string $mode = "rb"): bool
| Arguments | resource $zip, resource $entry, string $mode = "rb" |
|---|---|
| Return value | True if the entry opens successfully, otherwise false. |
This function supports all the access modes like "r", "rb", "w", "a", "x", etc., The default mode is Read Only Binary Mode ("rb") and it behaves as Read Only Binary Mode even though the Zip Archive is opened in a "x" access mode.
A classroom kiosk previews a note directly from a handout archive. The reader must open the selected member in binary read mode before asking for its contents.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo.zip");
if (!is_resource($zipHandler)) {
return;
}
while($zipEntry = zip_read($zipHandler)) {
/* Opening a File in a Zip Archive */
$flag = zip_entry_open($zipHandler, $zipEntry, "rb");
if ($flag == true) {
// Read the content of a file
$contents = zip_entry_read($zipEntry);
// Print the content of a file
echo($contents);
// close the file entry
zip_entry_close($zipEntry);
} else {
echo("Failed to Open. \n");
}
}
zip_close($zipHandler);
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
File: bbminfo/readme.txt Thousands Lived without Love, but not without water. So SAVE WATER.
A teacher saves the bytes for the word alto in an uncompressed archive member. Open the member by name and read its text. What does the teacher see?
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. Open the member by name and read its text. What does the teacher see?
The archive contains one stored member. Its entry metadata and contents can be inspected independently.
Reference: PHP manual — zip_entry_open()