Learn to Unzip a Zip file using PHP Script!


This post shows you how to Unzip a Zipped file using PHP. Its really simple using PHP ZIP extension.

Note this: This script works only If the ZIP extension installed in your PHP server.

PHP has built-in extensions for dealing with compressed files. Here is the script for you to play around:

//blog.theonlytutorials.com - unzip files using PHP
//author: agurchand

//create an object of ZipArchive Class
	$zip = new ZipArchive;
//open the file that you want to unzip. NOTE: give the correct path. In this example zip file is in the same folder	
	$zipped = $zip->open('phpzip.zip');

//give a folder name where the files has to be unzipped	
	$folder_name = 'unzip-folder';

//check if it is actually a Zip file	
	if ( $zipped ) {
//if yes then extract it to the said folder
	  $extract = $zip->extractTo($folder_name);

	  //if unzipped succesfully then show the success message
		echo "Your file extracted to $folder_name";
	  //close the zip

And also I have given a download for you to make it much easier 🙂



Leave a Reply

Theme: Overlay by Kaira
%d bloggers like this: