Created
December 28, 2015 19:09
-
-
Save micronax/9fb592e49c0af2b79e18 to your computer and use it in GitHub Desktop.
Small PHP-Script with GUI to unzip files in current directory
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 | |
echo '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">'; | |
echo '<div class="container" style="margin-top:50px;">'; | |
if (!class_exists('ZipArchive')) { | |
die("<h1>ZipArchive is not installed. Pleas echeck php.ini</h1>"); | |
} | |
if ($_GET['delete_me'] == 'true') { | |
unlink(__FILE__); | |
echo "<div class='alert alert-success'>Bye Bye!</div>"; exit; | |
} | |
if ($_GET['unzip_all'] == 'true') { | |
$files = glob('*.zip'); | |
foreach ($files as $file) { | |
$zip = new ZipArchive(); | |
if ($res = $zip->open($file)) { | |
$zip->extractTo('./'); | |
$zip->close(); | |
if ($_GET['delete'] == 'true') { | |
unlink($file); | |
} | |
} else { | |
echo "<div class='alert alert-danger'>Unzip failed!</div>"; | |
} | |
echo "<div class='alert alert-success'>Unzip successful!</div>"; | |
} | |
} | |
if ($unzip_file = $_GET['unzip_file']) { | |
$unzip_file = str_replace("/", "", $unzip_file); | |
if (!is_readable($unzip_file)) { | |
echo "<div class='alert alert-danger'>File cannot be opened!</div>"; | |
} | |
if (stripos('..', $unzip_file)) { | |
echo "<div class='alert alert-danger'>Illegal pattern!</div>"; | |
} | |
$zip = new ZipArchive(); | |
if ($res = $zip->open($unzip_file)) { | |
$zip->extractTo('./'); | |
$zip->close(); | |
echo "<div class='alert alert-success'>Unzip successful!</div>"; | |
if ($_GET['delete'] == 'true') { | |
unlink($unzip_file); | |
} | |
} else { | |
echo "<div class='alert alert-danger'>Unzip failed!</div>"; | |
} | |
} | |
echo "<h2>Zip-files in current dir</h2>"; | |
$files = glob('*.zip'); | |
echo "<table class='table table-striped'>"; | |
foreach ($files as $file) { | |
echo sprintf("<tr><td><b>%s</b></td> <td class='text-right'><div class='btn-group'><a href='?unzip_file=%s' class='btn btn-primary'>Unzip</a> <a href='?unzip_file=%s&delete=true' class='btn btn-danger'>Unzip & delete</a></div></td></tr>", $file, $file, $file); | |
} | |
echo "</table>"; | |
echo "<div class='text-right'><a href='?unzip_all=true'>Unzip all files</a> • <a href='?unzip_all=true&delete=true'>Unzip and delete all files</a> • <a href='?delete_me=true'>Delete this file</a></div>"; | |
echo "<hr><div class='text-right small text-muted'>Copyright © 2015 <a href='http://www.fabian-golle.de'>Fabian Golle IT</a>. All rights reserved.</a>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment