PHP | zip_close( ) Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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");
}
  
?>

chevron_right


Output:

Zip Archive File is Successfully Opened.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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");
  
?>

chevron_right


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



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.