Extract zip file using php with Zip extension

Extract zip files using zip extension of php

Below code is works if you server has installed zip extension of php

For example please check below image, if you want to check your server is support or not, use phpinfo() function.

$file = $_REQUEST['file'];
$zip = new ZipArchive;
if ($zip->open($file) === true) {
for($i = 0; $i < $zip->numFiles; $i++) {
if($zip->extractTo('extract/', array($zip->getNameIndex($i)))){
echo "<br />extract".$zip->getNameIndex($i);
} else {
echo "<br />not extract".$zip->getNameIndex($i);


Now if you want to access/run above code, you need to pass one argument for file name check below link


If above script not extract all files in destination folder(extract), almost you have not created destination folder in server or problem of pemissions(777).

Posted in php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s