Skip to content

Instantly share code, notes, and snippets.

@fhdalikhan
Created January 28, 2021 17:57
Show Gist options
  • Save fhdalikhan/7487b1fbe27c9ca7c6242ab384ab2b74 to your computer and use it in GitHub Desktop.
Save fhdalikhan/7487b1fbe27c9ca7c6242ab384ab2b74 to your computer and use it in GitHub Desktop.
Extract zip file
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'text.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 "Success! $file extracted to $path";
} else {
echo "Error! couldn't open $file";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment