Open In App

PHP | zip_close( ) Function

Last Updated : 17 Jul, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The zip_close() function is an inbuilt function in PHP which is used to close a zip archive file opened by the zip_open() function. The zip_close() causes the stream to be closed and the connection to the corresponding Zip Archive to be broken. The zip resource which has been opened by the zip_open() function is sent as a parameter to the zip_close() function and it returns no value. Syntax:
void zip_close ( $zip_file )
Parameters: The zip_close() function accepts single parameter $zip_file. It is a mandatory parameter which specifies the zip file resource to be closed. Return Value: It does not return any value. Errors And Exceptions:
  • The zip Archive to be closed must be opened first by using the PHP zip_open() function otherwise the PHP zip_close() function produces a PHP warning.
  • The zip_close() function returns an ER_OPEN error if the zip archive is invalid.
  • The zip_close() function returns an ER_NOZIP error if the zip archive is empty.
Below programs illustrate the zip_close() function in PHP: Program 1: php
<?php

// Opening zip archive's file
$zip_file = zip_open("article.zip");

if(is_resource($zip_file))
{ 
    echo("Zip Archive File is Successfully Opened.");
    
    // Closing zip archive's handle
    zip_close($zip_file);
} 
else
{
    echo($zip_file . " Archive File Cannot Be Opened");
}

?>
Output:
Zip Archive File is Successfully Opened.
Program 2: php
<?php

// Opening zip archive's file
$zip_file = zip_open("article.zip");

if(is_resource($zip_file)) 
{ 
    while($zipfiles = zip_read($zip_file)) 
    { 
        $file_name = zip_entry_name($zipfiles);
        echo("File Name: " . $file_name . "<br>");
    } 
    
    // Closing zip archive's
    zip_close($zip_file);
} 
else
{
    echo($zip_file . " Archive File Cannot Be Opened");
} 

?>
Output:
File Name: article/content.xlsx
File Name: article/gfg.pdf
File Name: article/image.jpeg
Reference : http://php.net/manual/en/function.zip-close.php

Next Article
Practice Tags :

Similar Reads