PHP zip_entry_close - Syntax
zip_entry_close(resource $ziphandler): bool
The PHP zip_entry_close() 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_close(resource $ziphandler): bool
resource $zipHandler |
Specifies the Resource Handler of a Zip Archive file (*Required) |
---|---|
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.
The PHP zip_entry_close() function closes the specified directory entry. It's is a good programming practice to clear the used buffer memory allocated by PHP zip_entry_open() function. Moreover zip archive entry must be opened first by using the PHP zip_entry_open() function, otherwise the PHP zip_entry_close function throw the PHP Warning.
Open only a text file in a zip archieve using zip_entry_close 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();