Created
July 22, 2012 21:05
-
-
Save lamprosg/3161045 to your computer and use it in GitHub Desktop.
Unzip a Zip File in PHP
This file contains hidden or 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
| //Use the code as following: | |
| <?php | |
| include 'unzip.php'; | |
| if(unzip('zipedfiles/test.zip','unziped/myNewZip')) | |
| echo 'Success!'; | |
| else | |
| echo 'Error'; | |
| ?> |
This file contains hidden or 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 | |
| //$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