Unzip a Zip file using Php


Welcome back to shortlearner.com, Most of the time we need a software like winrar , which are helped us to unzip or extract our zip file . In today’s  tutorial we will see how to unzip a zip file with the help of some predefined php function.

unzip a file using php

in the below code i have created a function called unzipmyfile which have two parameter $file and another one is  $location . in $file we have passed a zip file name with . zip extension and  $location we declare a suitable path where extracted file should be placed.

Want to learn : How to check file size using php

Import Data from text file to mysql database

Read XML FILE using Php

Php provide us a predefined function called  ZipArchive::extractTo . with the help of this function we can easily extract zip archive.



function unzipmyfile($file,$location){
	$zip = new ZipArchive;
		return "success" ;
		return "fail";

Now we call this function and pass two parameter, zip file and location where extracted file should be placed.

Also Learn :  Print Numbers from 1 to N without using Loop

Make Facebook Like Chat System Using Php , Mysql And Ajax

Insert a Html content in database using Php

$file= "update_ajax_tutorial.zip";
echo unzipmyfile($file,$location);