Unzip Zip file using php

This is a quick tutorial to Unzip Zip file using php, Here I have created a quick function in php to extract zip file, Unzipping file is now very easy using php, In php there is a function called ZipArchive::extractTo, using this predefined function you can easily extract zip archive.

Here is the function..


  function unzip($file, $location) {
    $zip = new ZipArchive;
	if ($zip->open($file) === TRUE) {
	    return "Success";
	} else {
	    return 'failed';

Now call this function anywhere you want and pass tow parameter, zip file and destination path where extracted file should be placed.

 $file = 'jnoti.zip';
 $location = "extractZip/";
 echo unzip($file, $location);

If you like this post please don’t forget to subscribe my public notebook for more useful stuff

Posted in PHP