Skip to content

Instantly share code, notes, and snippets.

@dipenparmar12
Created March 29, 2022 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipenparmar12/53cbd8184530ca72db89a3e7d21819f8 to your computer and use it in GitHub Desktop.
Save dipenparmar12/53cbd8184530ca72db89a3e7d21819f8 to your computer and use it in GitHub Desktop.
PHP Script to Extract Zip file
<?php
try {
$input_zip = $_GET["filename"];
$target_dir = $_GET["target_dir"] ?? "./";
echo "Starting...";
if (!is_file($input_zip) || !is_readable($target_dir)) {
die("Can't Read Input");
}
if (!is_dir($target_dir) || !is_writable($target_dir)) {
die("Can't Write to Target");
}
$zipArchive = new ZipArchive();
$result = $zipArchive->open($input_zip);
if ($result === TRUE) {
$zipArchive->extractTo($target_dir);
$zipArchive->close();
echo "Success";
// Do something else on success
return true;
} else {
die("Went Wrong");
}
}
//catch exception
catch (Exception $e) {
echo 'Message: ' . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment