PHP zip_entry_open - Syntax
zip_entry_open(resource $zipHandler, resource $zipEntry[, string $mode]): bool
The PHP zip_entry_open() function is used to open the specified file (or) directory in a Zip Archive. It return true only if the file in a Zip Archive is opened Successfully otherwise false.
zip_entry_open(resource $zipHandler, resource $zipEntry[, string $mode]): bool
resource $zipHandler |
Specifies the Resource Handler of a Zip Archive file (*Required) |
---|---|
resource $zipEntry |
Specifies the Resource Handler of a File in a Zip Archive. (*Required) |
string $mode |
Specifies the type of access of a File in a Zip Archive. |
Return bool $flag |
Returns true on success 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.
Open only a text file in a zip archieve using zip_entry_open library method in rb mode, Print the content of a file only if the file was opened successfully otherwise print an error message.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo.zip");
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();