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
- neveropen.png
- neveropen1.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/neveropen.png File Name: article/img/neveropen1.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