Skip to content

Instantly share code, notes, and snippets.

@decebal
Created July 2, 2012 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decebal/3033427 to your computer and use it in GitHub Desktop.
Save decebal/3033427 to your computer and use it in GitHub Desktop.
Unzip with php
<?php
function unzip($location,$newLocation){
if(exec("unzip $location",$arr)){
mkdir($newLocation);
for($i = 1;$i< count($arr);$i++){
$file = trim(preg_replace("~inflating: ~","",$arr[$i]));
copy($location.'/'.$file,$newLocation.'/'.$file);
unlink($location.'/'.$file);
}
return TRUE;
}else{
return FALSE;
}
}
?>
//Use the code as following:
<?php
include 'functions.php';
if(unzip('zipedfiles/test.zip','unziped/myNewZip'))
echo 'Success!';
else
echo 'Error';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment