BBM Tutor
BBM Tutor

PHP Zip - zip_entry_close()

Description & Uses of PHP zip_entry_close()

The PHP zip_entry_close() function causes the stream to be closed and the connection to the corresponding Zip Archive Entry (a file or a directory within the Zip Archive) to be broken.

Simple Example - PHP zip_entry_close(Resource $zip_entry);

PHP Input Screen

<?php
$ZipHandler = zip_open("./Invoice.zip");
$zipEntry = zip_read($ZipHandler);
zip_entry_open($ZipHandler, $zipEntry, "rb");
$file_Name = zip_entry_name($zipEntry);

/* Closing a File in a Stream for a Zip Archive */
$flg = zip_entry_close($zipEntry);
if ($flg == true) {
echo("File Name: " . $file_Name . " is Closed Successfully. ");
} else{
echo("Failed to Close.");
}

zip_close($ZipHandler);
?>

PHP Output Screen

File Name: Invoice.txt is Closed Successfully.

bbminfo Demo Zip Archive File: Invoice.zip

  • It contains the following file
    • Invoice.txt
  • Download the Demo Zip Archive File: Invoice.zip for your tutorial reference purpose.
BBM Invoice

Simple PHP Syntax

<?php
zip_entry_close(Resource $zip_entry);
?>

Parameter & Return Type

Description

Resource $ziphandler
Specifies the Resource Handler of an already opened Zip Archive File. (*Required)
Return Boolean $flg
Returns TRUE on success otherwise FALSE.

What is PHP zip_entry_close()?

  • The connection between the stream and the Zip Archive Entry (a File or a directory within a Zip Archive) is cancelled.
  • It returns TRUE on Success otherwise FALSE.
  • The Zip Archive Entry must be opened first by using the PHP zip_entry_open() function, otherwise the PHP zip_entry_close function produce the PHP Warning.
  • Resource Handler of a Zip Archive Entry (a FIle or a Directory within a Zip Archive) must be closed to avoid unwanted (or) unexpected changes during the program execution.
  • It's is a good programming practice to clear the used buffer memory allocated by PHP zip_entry_open() function.
  • Closing of an Invalid or an Empty Resource Handler leads to PHP Warning and it returns FALSE.
BBM Invoice

Example 1 - PHP zip_entry_close(Resource $zip_entry);

PHP Input Screen

<?php
$ZipHandler = zip_open("./YGen.zip");
if(is_resource($ZipHandler)) {
while($zipEntry = zip_read($ZipHandler)) {
$Entry_flg = zip_entry_open($ZipHandler, $zipEntry, "rb");
$file_Name = zip_entry_name($zipEntry);
if ($Entry_flg == true) {
echo("File Name: " . $file_Name . " is Opened Successfully. ");
echo "<br>" ;

/* Closing a File in a Stream for a Zip Archive */
$flg = zip_entry_close($zipEntry);
if ($flg == true) {
echo("File Name: " . $file_Name . " is Closed Successfully. ");
} else{
echo("Failed to close.");
}

echo "<br>" ;
} else{
echo("Failed to Open.");
}
}
zip_close($ZipHandler);
} else {
echo("Failed to Open. Error Code: " . $ZipHandler);
}
?>

PHP Output Screen

File Name: YGen.jpg is Opened Successfully.
File Name: YGen.jpg is Closed Successfully.

File Name: YGen.pdf is Opened Successfully.
File Name: YGen.pdf is Closed Successfully.

File Name: YGen.txt is Opened Successfully.
File Name: YGen.txt is Closed Successfully.

bbminfo Demo Zip Archive File: YGen.zip

  • It contains 3 Files, they are
    • YGen.jpg
    • YGen.pdf
    • YGen.txt
  • Download the Demo Zip Archive File: YGen.zip for your tutorial reference purpose.
BBM Invoice
 
Disclaimer: Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.