PHP zip_close - Syntax
zip_close(resource $zip): void
zip_close() closes an open ZIP archive and releases its resource. PHP deprecated this procedural function in 8.0. For new code, use ZipArchive::close().
zip_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_close(resource $zip): void
| Arguments | resource $zip |
|---|---|
| Return value | No return value. |
A course editor inventories a bundle of handouts before making it available to students. Once the last entry has been listed, the script releases the archive handle.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo.zip");
if(is_resource($zipHandler)) {
while($zipEntry = zip_read($zipHandler)) {
$fileName = zip_entry_name($zipEntry);
echo("File Name: " . $fileName);
echo "\n" ;
}
zip_close($zipHandler);
} else {
echo("Failed to Open. Error Code: " . $zipHandler);
}
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
File Name: readme.txt
A librarian is diagnosing a handout bundle that fails during opening. Check the resource returned by the open operation before deciding whether there is a handle to close.
<?php
class ZipExample {
public function processZipArchieve() {
/* Invalid zip archieve or an invalid file path */
$zipHandler = zip_open("./invaid.zip");
zip_close($zipHandler);
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
Warning: zip_close() expects parameter 1 to be resource, null given in ~\zip-example.php on line 9
A teacher saves the bytes for the word alto in an uncompressed archive member. The reader finishes its work and closes the archive handle. 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_close()