Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created July 22, 2012 21:05
Show Gist options
  • Select an option

  • Save lamprosg/3161045 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/3161045 to your computer and use it in GitHub Desktop.
Unzip a Zip File in PHP
//Use the code as following:
<?php
include 'unzip.php';
if(unzip('zipedfiles/test.zip','unziped/myNewZip'))
echo 'Success!';
else
echo 'Error';
?>
<?php
//$location is current location of the zipped file
//#bewLocation is the directory where the unzipped files will be stored
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;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment