Skip to content

Instantly share code, notes, and snippets.

@yasaryousuf
Created December 22, 2018 10:57
Show Gist options
  • Save yasaryousuf/626f4c1989375bf898620daa3d5b8cd4 to your computer and use it in GitHub Desktop.
Save yasaryousuf/626f4c1989375bf898620daa3d5b8cd4 to your computer and use it in GitHub Desktop.
<?php
// config
// -------------------------------
// only file name + .zip
$zip_filename = $_POST['zip_filename'] ?? '';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' >
<title>Unzip</title>
<style>
body{
font-family: arial, sans-serif;
word-wrap: break-word;
}
.wrapper{
padding:20px;
line-height: 1.5;
font-size: 1rem;
}
span{
font-family: 'Consolas', 'courier new', monospace;
background: #eee;
padding:2px;
}
</style>
</head>
<body>
<div class="wrapper">
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
<input type="text" name="zip_filename" placeholder="Zip file name" size="65"><input type="submit" name="" value="Unzip">
</form>
<?php
if (!$zip_filename) {
return;
}
elseif (!class_exists('ZipArchive')) {
return;
}
$dirname = pathinfo($zip_filename, PATHINFO_DIRNAME);
echo "Unzipping <span>". $zip_filename. "</span> to <span>" .$dirname. "</span><br>";
echo "current dir: <span>" . $dirname . "</span><br>";
$zip = new ZipArchive;
$res = $zip->open($zip_filename);
if ($res === TRUE) {
$zip->extractTo($dirname);
$zip->close();
echo '<p style="color:#00C324;">Extract was successful! Enjoy ;)</p><br>';
} else {
echo '<p style="color:red;">Zip file not found!</p><br>';
}
?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment