Your Ad Here

Home » PHP Code »

1

Use the following code to unzip the zip file using php code:

<?php
function unzip($location,$newLocation){
if(exec(“unzip $location”,$arr)){
mkdir($newLocation);
chmod($newLocation,0777);
for($i = 1;$i< count($arr);$i++){
$file = trim(preg_replace(“~inflating: ~”,”",$arr[$i]));
chmod($file,0777);
copy($file,$newLocation.’/’.$file);
//
unlink($file);
}
return TRUE;
}else{
return FALSE;
}
}
?>
//Use the code as following:
<?php

if(unzip(‘zip-file.zip’,'unZipFile’))
echo ‘Success!’;
else
echo ‘Error’;
?>

Hope that this will be useful.


You may like these posts

    PHP graphs using google visualizations chart apiHow to remove consecutive whitespaces using php?How to get loaded modules in the server using php codeMake thumb using php with respect the ratio width and  height

 

1 Comment

  1. If you interested to write an article on 9lessons as a guest author plz send the document.

Leave a Reply