Created
January 4, 2018 12:52
-
-
Save OkoyaUsman/d3f2dd31c32e2f548b3ec7fbc87952e3 to your computer and use it in GitHub Desktop.
Unzip a ZIP file using 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
<?php | |
/* | |
Here I have created a quick function in php to extract zip file. | |
Unzipping file is now very easy using php. | |
In php there is a function called ZipArchive::extractTo, using this predefined function you can easily extract zip archive. | |
*/ | |
function unzip($file, $location) { | |
$zip = new ZipArchive; | |
if ($zip->open($file) === TRUE) { | |
$zip->extractTo($location); | |
$zip->close(); | |
return "Success"; | |
} else { | |
return 'failed'; | |
} | |
} | |
// Now you call this function anywhere you want and pass two parameters. | |
// The zip file and destination path where extracted file should be placed. | |
$file = 'github.zip'; | |
$location = "assets/"; | |
echo unzip($file, $location); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment