BBM Tutor
BBM Tutor

PHP Zip - zip_entry_open()

Description & Uses of PHP zip_entry_open()

The PHP zip_entry_open() function is used to open the specified file (or) directory in a Zip Archive. It return TRUE only if the file in a Zip Archive is opened Successfully otherwise FALSE.

Simple Example - PHP zip_entry_open(Resource $ZipHandler, Resource $zipEntry, String $mode);

PHP Input Screen

<?php
$ZipHandler = zip_open("./Invoice.zip");
while($zipEntry = zip_read($ZipHandler)) {
/* Opening a File in a Zip Archive */
$flg = zip_entry_open($ZipHandler, $zipEntry, "rb");
$file_Name = zip_entry_name($zipEntry);
if ($flg == true) {
echo("File Name: " . $file_Name . " is opened Successfully. ");
zip_entry_close($zipEntry);
} else{
echo("Failed to Open.");
}
}
zip_close($ZipHandler);
?>

PHP Output Screen

File Name: Invoice.txt is opened 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_open(Resource $ZipHandler, Resource $zipEntry, String $mode);
?>

Parameter & Return Type

Description

Resource $ZipHandler
Specifies the Resource Handler of a Zip Archive File. (*Required)
Resource $zipEntry
Specifies the Resource Handler of a File in a Zip Archive. (*Required)
String $mode
Specifies the type of access of a File in a Zip Archive.
Return Boolean $flg
Returns TRUE on success otherwise FALSE.

What is PHP zip_entry_open() ?

  • Opening a file or a directory in a Zip Archive with the¬†zip_entry_open¬†function creates a new stream and establishes a connection between the stream and a file or a directory in a Zip Archive.
  • This function opens the specified Zip Archive entries like a file or a directory.
  • This function supports all the access modes like "r", "rb", "w", "a", "x", etc., but it treats every modes as a Read Only Binary Mode ("rb") even though the Zip Archive is opened in a "x" access mode.
  • By default it open the entries in "rb" (Read-Only Binary Mode), because Zip Archive is a non text file type.
  • No general functions are there to create or change the entries in a Zip Archive.
  • It return TRUE, if the file in a Zip Archive is open otherwise FALSE.
BBM Invoice

Example #1 - PHP zip_entry_open(Resource $ZipHandler, Resource $zipEntry, String $mode);

PHP Input Screen

<?php
$ZipHandler = zip_open("./YGen.zip");
if(is_resource($ZipHandler)) {
while($zipEntry = zip_read($ZipHandler)) {
/* Opening a File in a Zip Archive */
$flg = zip_entry_open($ZipHandler, $zipEntry, "rb");
$file_Name = zip_entry_name($zipEntry);
if ($flg == true) {
echo("File Name: " . $file_Name . " is opened Successfully. ");
echo "<br>" ;
zip_entry_close($zipEntry);
} else {
echo("Failed to Open.");
echo "<br>" ;
}
}
/* Zip Archive's Resource Handler Closing Operation */
zip_close($ZipHandler);
} else {
echo("Failed to Open. Error Code: " . $ZipHandler);
}
?>

PHP Output Screen

File Name: YGen.jpg is opened Successfully.
File Name: YGen.pdf is opened Successfully.
File Name: YGen.txt is opened 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

Example #2 - PHP zip_entry_open(Resource $ZipHandler, Resource $zipEntry, String $mode);

PHP Input Screen

<?php
$ZipHandler = zip_open("./BBMINFO.zip");
if(is_resource($ZipHandler)) {
while($zipEntry = zip_read($ZipHandler)) {
/* Opening a File in a Zip Archive */
$flg = zip_entry_open($ZipHandler, $zipEntry, "rb");
$file_Name = zip_entry_name($zipEntry);
if ($flg == true) {
echo("File Name: " . $file_Name . " is opened Successfully. ");
echo "<br>" ;
zip_entry_close($zipEntry);
} else {
echo("Failed to Open.");
echo "<br>" ;
}
}
zip_close($ZipHandler);
} else {
echo("Failed to Open. Error Code: " . $ZipHandler);
}

?>

PHP Output Screen

File Name: YGen/YGen.jpg is opened Successfully.
File Name: YGen/YGen.pdf is opened Successfully.
File Name: YGen/YGen.txt is opened Successfully.
File Name: BBMINFO.jpg is opened Successfully.
File Name: Invoice/Features/ is opened Successfully.
File Name: Invoice/Features/KeyFeatures.rtf is opened Successfully.
File Name: Invoice/Invoice.txt is opened Successfully.

bbminfo Demo Zip Archive File: BBMINFO.zip

  • It contains 2 Directories & 1 File, they are
    • Directory : YGen contains 3 Files, they are
      • YGen.jpg
      • YGen.pdf
      • YGen.txt
    • Directory : Invoice contains 1 Sub Directory & 1 File
      • Directory : Features contains 1 File
        • KeyFeatures.rtf
      • Invoice.txt
    • BBMINFO.jpg
  • Download the Demo Zip Archive File: BBMINFO.zip for your tutorial reference purpose.
BBM Invoice

Example #3 - PHP zip_entry_open(Resource $ZipHandler, Resource $zipEntry, String $mode);

PHP Input Screen

<?php
$ZipHandler = zip_open("./EmptyBoxOut.zip");
if(is_resource($ZipHandler)) {
while($zipEntry = zip_read($ZipHandler)) {
/* Opening a File in a Zip Archive */
$flg = zip_entry_open($ZipHandler, $zipEntry, "rb");
$file_Name = zip_entry_name($zipEntry);
if ($flg == true) {
echo("File Name: " . $file_Name . " is opened Successfully. ");
echo "<br>" ;
zip_entry_close($zipEntry);
} else {
echo("Failed to Open.");
echo "<br>" ;
}
}
zip_close($ZipHandler);
} else {
echo("Failed to Open. Error Code: " . $ZipHandler);
}
?>

PHP Output Screen

File Name: EmptyBox.zip is opened Successfully.

bbminfo Demo Zip Archive File: EmptyBoxOut.zip

  • It contains 1 File:
    • EmptyBox.zip
  • Download the Demo Zip Archive File: EmptyBoxOut.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.