Skip to content

Instantly share code, notes, and snippets.

@sarathlal-old
Last active November 26, 2015 05:12
Show Gist options
  • Save sarathlal-old/20dcf2beb80529d63218 to your computer and use it in GitHub Desktop.
Save sarathlal-old/20dcf2beb80529d63218 to your computer and use it in GitHub Desktop.
Unzip .zip archive using PHP
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'mrkothari.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