PHP zip_entry_close - Syntax
zip_entry_close(resource $entry): bool
zip_entry_close() closes the current ZIP entry. PHP deprecated this procedural function in 8.0. Use fclose on a stream returned by ZipArchive::getStream in new code.
zip_entry_close()
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_close(resource $entry): bool
| Arguments | resource $entry |
|---|---|
| Return value | True on success or false on failure. |
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.
A music teacher previews a text member inside a pack of rehearsal materials. Close the member after reading it so the next part can be opened in the same archive.
<?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. File was closed successfully.
A teacher saves the bytes for the word alto in an uncompressed archive member. The reader finishes its work and closes the member stream. What is the state of that resource?
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. The reader finishes its work and closes the member stream. What is the state of that resource?
The archive contains one stored member. Its entry metadata and contents can be inspected independently.
Reference: PHP manual — zip_entry_close()