Thursday, August 28, 2025
HomeLanguagesPHP | zip_close( ) Function

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:




<?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
  
// 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32236 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6609 POSTS0 COMMENTS
Nicole Veronica
11779 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11828 POSTS0 COMMENTS
Shaida Kate Naidoo
6719 POSTS0 COMMENTS
Ted Musemwa
7002 POSTS0 COMMENTS
Thapelo Manthata
6678 POSTS0 COMMENTS
Umr Jansen
6690 POSTS0 COMMENTS