PHP zip_close - Syntax
zip_close(Resource $ziphandler): void
The PHP zip_close() function causes the stream to be closed and the connection to the corresponding Zip Archive to be broken. It's is a good programming practice to clear the used buffer memory allocated by PHP zip_close() function.
zip_close(Resource $ziphandler): void
resource $ziphandler |
Specifies the Resource Handler of an already opened Zip archive file (*Required) |
---|---|
Return void |
void (i.e. function doesn't return a value) |
Close the already opened zip archieve's resource handler using zip_close funtion.
<?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();
Try to close an invalid resource handler, it will throw a PHP warning.
<?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();