PHP | zip_entry_name() Function

The zip_entry_name() function is an inbuilt function in PHP which is used to return the name of a zip archive entry. The zip entry resource is to be read and sent as a parameter to the zip_entry_name() function and it returns the name of the zip entry archive on Success.
Syntax:
string zip_entry_name( $zip_entry )
Parameters: This function accepts single parameter $zip_entry which is mandatory. It is used to specify the zip entry resource.
Return Value: It returns the name of a zip archive entry on Success.
Errors And Exceptions:
- The zip_entry_name() returns the name of a zip entry archive only on Success otherwise it returns a PHP warning.
- The zip_entry_name() function returns an ER_OPEN error if the zip archive is invalid.
- The zip_entry_name() function returns an ER_NOZIP error if the zip archive is empty.
Below programs illustrate the zip_entry_name() function in PHP:
Program 1:
Suppose a zip file article.zip contains the following file:
content.xlsx
| <?php  Â// Opening a zip file $zip_handle= zip_open("C:/xampp/htdocs/article.zip");  Â// Reading a zip entry archive  $zip_entry= zip_read($zip_handle);   Â// Reading the name of a zip entry archive $file= zip_entry_name($zip_entry); echo("File Name: ". $file);  Â// Closing the zip archive zip_close($zip_handle); ?>  | 
Output:
File Name: article/content.xlsx
Program 2:
Suppose a zip file article.zip contains following files and directories:
Directory: img
- zambiatek.png
- zambiatek1.png
content.xlsx
gfg.pdf
image.jpeg
| <?php  Â// Opening a zip file $zip_handle= zip_open("C:/xampp/htdocs/article.zip");  Âif(is_resource($zip_handle))  {      while($zip_entry= zip_read($zip_handle))      {          $file= zip_entry_name($zip_entry);         Â        // Checking the file name of a zip archive entry          $file_name= zip_entry_name($zip_entry);         echo("File Name: ". $file_name. "<br>");     }      Â    // closing the zip archive    zip_close($zip_handle); }  else    echo("Zip archive cannot be read."); ?>  | 
Output:
File Name: article/content.xlsx File Name: article/gfg.pdf File Name: article/image.jpeg File Name: article/img/ File Name: article/img/zambiatek.png File Name: article/img/zambiatek1.png
Related Articles:
- PHP | zip_read() Function
- PHP | zip_close( ) Function
- PHP | zip_entry_close() Function
- PHP | zip_entry_compressedsize() Function
Reference: http://php.net/manual/en/function.zip-entry-name.php
 
				 
					


