Created
March 29, 2022 08:04
-
-
Save dipenparmar12/53cbd8184530ca72db89a3e7d21819f8 to your computer and use it in GitHub Desktop.
PHP Script to Extract Zip file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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