0 points

extract a zip to folder


dashboard

Wed May 20 2020 19:53:26 GMT+0000 (UTC)

Posted by @isalmanhaider@gmail.com #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";
}
content_copy

Very handy code snippet! Some servers where you don't have the option to upload 100mb + files from the Cpanel or file manager, so upload a zip via FileZilla and then this script into extract.php putting it on a same level as of the zip. and execute it through the browser. It will extract the zip to the folder.



>> Browse more code snippets

more_vert