How to read the zip content in php?

To read the zip content in php, you should have your zip extension enabled first. The extension is located in /php/ext directory. To enable it add this line to php.ini file.
extension = php_zip.dll

Once you have your extension enabled, you could use the php built in function to open and read the zip content. Here is the small example to read multiple files contained in the zip.

 function read_zip_file($zipfile) {
 $zip = zip_open($zipfile);

 if(is_resource($zip)) {
	while(($zip_entry = zip_read($zip))) {
		$filename = basename(zip_entry_name($zip_entry));
		$entry_content = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

		$each_file_content[$filename] = $entry_content;
 }else {
	echo 'Invalid Zip Format';

Leave a Reply

Your email address will not be published. Required fields are marked *