Skip to content

Instantly share code, notes, and snippets.

@OkoyaUsman
Created January 4, 2018 12:52
Show Gist options
  • Save OkoyaUsman/d3f2dd31c32e2f548b3ec7fbc87952e3 to your computer and use it in GitHub Desktop.
Save OkoyaUsman/d3f2dd31c32e2f548b3ec7fbc87952e3 to your computer and use it in GitHub Desktop.
Unzip a ZIP file using php
<?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