PHP Function Reference

PHP zip_close() Function



The PHP zip_close() function is used to close the given ZIP file archive.

Note: This function has been DEPRECATED as of PHP 8.0.0. The procedural API is deprecated and ZipArchive should be used instead.

Syntax

zip_close(zip)

Parameters

zip Required. Specify a ZIP file previously opened with zip_open().

Return Value

No value is returned.

Example: open and close an archive

Lets assume that we have a zip file called example.zip which contains the following files:

test.txt
example.csv
image.png

The example below demonstrates how to open and close this zip file:

<?php
//opening the zip file
$zip = zip_open("example.zip");
  
if(is_resource($zip)) { 
  echo 'Zip file opened successfully.';
      
  //closing the zip file
  zip_close($zip);
} else {
  echo 'Opening of the Zip file failed.';
}
?>

The output of the above code will be:

Zip file opened successfully.

Example: getting all file names of an archive

The example below describes how to get all file names of a given archive.

<?php
//opening the zip file
$zip = zip_open("example.zip");
  
if(is_resource($zip)) { 
  while($zipfiles = zip_read($zip)) { 
    $file_name = zip_entry_name($zipfiles);
    echo("File Name: $file_name \n");
  } 
      
  //closing the zip file
  zip_close($zip);
} else {
  echo 'Opening of the Zip file failed.';
}
?>

The output of the above code will be:

File Name: example/test.txt
File Name: example/example.csv
File Name: example/image.png

❮ PHP Zip Reference