PHP zip_read() Function
The PHP zip_read() function is used to read the next entry in a 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_read(zip)
Parameters
zip |
Required. Specify a ZIP file previously opened with zip_open(). |
Return Value
Returns a directory entry resource for later use with the zip_entry_... functions, or false if there are no more entries to read, or an error code if an error occurred.
Example: getting all file names of 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 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