PHP | zip_open() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The zip_open() function is an inbuilt function in PHP which is used to open a zip archive for reading. The zip_open() function creates a new stream and establishes a connection between the stream and a Zip Archive. The filename is sent as a parameter to the zip_open() function and it returns a valid resource handler if the zip archive file is opened successfully otherwise it returns an Error. Syntax: zip_open( $filename ) Parameters: This function accepts single parameter $filename which is mandatory. It is used to specify the zip resource to be opened. Return Value: It returns a valid resource handler if the zip archive file is opened successfully otherwise it returns an Error. Errors And Exceptions: The zip_open() function returns an ER_OPEN error if the zip archive is invalid. The zip_open() function returns an ER_NOZIP error if the zip archive is empty. Below programs illustrate the zip_open() function in PHP: Suppose a zip file article.zip contains the following files: article.zip content.xlsx gfg.pdf image.jpeg Program 1: php <?php // Opening zip file $my_zip = zip_open("article.zip"); if(is_resource($my_zip)) { echo("Zip file opened successfully."); // Closing zip file zip_close($my_zip); } else echo($my_zip . "file can not be opened"); ?> Output: Zip file opened successfully. Program 2: php <?php // Opening zip file $my_zip= zip_open("article.zip"); if(is_resource($my_zip)) { while($zipfiles = zip_read($my_zip)) { $file_name = zip_entry_name($zipfiles); echo("File Name: " . $file_name . "<br>"); } // Closing zip file zip_close($my_zip); } else echo($my_zip . "file Can not be opened"); ?> Output: File Name: article/article.zip File Name: article/content.xlsx File Name: article/gfg.pdf File Name: article/image.jpeg Related Articles: PHP | zip_close( ) Function PHP | zip_entry_compressionmethod() Function PHP | zip_entry_close() Function Reference: https://www.php.net/manual/en/function.zip-open.php Comment More infoAdvertise with us Next Article PHP finfo_open() Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-file-handling PHP-function +1 More Practice Tags : Misc Similar Reads PHP | zip_entry_open() Function The zip_entry_open() function is an inbuilt function in PHP which is used to open a zip entry archive for reading. 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 A 3 min read PHP | opendir() Function The opendir() function in PHP is an inbuilt function which is used to open a directory handle. The path of the directory to be opened is sent as a parameter to the opendir() function and it returns a directory handle resource on success, or FALSE on failure. The opendir() function is used to open up 2 min read PHP finfo_open() Function The finfo_open() function is an inbuilt function in PHP that creates a new info instance. This function is in PHP 7 and 8. Syntax: Procedural Style:finfo_open(Flag, magic_database = null)Object-Oriented Style:public finfo::__construct(Flag, $magic_database = null)Parameters: This function has only t 1 min read PHP | zip_read() Function The zip_read() function is an inbuilt function in PHP which is used to read an entity present in the opened zip archive. The zip resource is to be read and sent as parameters to the zip_read() function and it returns a resource containing file within the zip archive on success, or FALSE if there is 2 min read 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_nam 2 min read PHP | XMLWriter openUri() Function The XMLWriter::openUri() function is an inbuilt function in PHP which is used to create a new XMLWriter using source URI for output. In simple words, this function decides how to output the XML to user, it can be through a browser or directly to a file. Syntax: bool XMLWriter::openUri( string $uri ) 2 min read Like