Skip to content

Instantly share code, notes, and snippets.

@azharisubroto
Created September 4, 2016 17:31
Show Gist options
  • Save azharisubroto/2e1adf6781bc8e81752ddbf4cfc3daad to your computer and use it in GitHub Desktop.
Save azharisubroto/2e1adf6781bc8e81752ddbf4cfc3daad to your computer and use it in GitHub Desktop.
Thanks to rdlowrey at stackoverflow. http://stackoverflow.com/a/8889126
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'file.zip';
// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
// extract it to the path we determined above
$zip->extractTo($path);
$zip->close();
echo "WOOT! $file extracted to $path";
} else {
echo "Doh! I couldn't open $file";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment