Created
May 20, 2012 20:45
-
-
Save apphp-snippets/2759472 to your computer and use it in GitHub Desktop.
This code allows you to Unzip a ZIP file with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Source: http://www.apphp.com/index.php?snippet=php-get-remote-ip-address */ | |
function unzip($location,$new_location){ | |
if(exec("unzip $location",$arr)){ | |
mkdir($new_location); | |
for($i = 1;$i< count($arr);$i++){ | |
$file = trim(preg_replace("~inflating: ~","",$arr[$i])); | |
copy($location."/".$file,$new_location."/".$file); | |
unlink($location."/".$file); | |
} | |
return true; | |
} | |
return false; | |
} | |
// usage of this code | |
if(unzip('ziped_files/test.zip','unziped_files/newfile')){ | |
echo 'Successfully unzipped!'; | |
}else{ | |
echo 'Error while processing your file!'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment