Created
January 18, 2014 16:14
-
-
Save cukabeka/8492556 to your computer and use it in GitHub Desktop.
A useful blend of http://www.bjw.co.nz/developer/php/62-php-unzip-an-uploaded-file-using-php and http://geekery.the-kid.org/myscripts/php-unzipper/
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-UK"> | |
<head> | |
<title>Buki's Unzipper Script</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<meta name="generator" content="thekid" /> | |
<meta name='robots' content='noindex,nofollow' /> | |
</head> | |
<body> | |
<?php | |
$file = $_GET['file']; | |
$removeorig = $_GET['removeorig']; | |
$unzipper = $_GET['unzipper']; | |
if (isset($file)) | |
{ | |
echo "Unzipping " . $file . "...<br />\n"; | |
$zip = new ZipArchive; | |
$res = $zip->open($file); | |
if ($res === TRUE) { | |
$zip->extractTo('_unzip/'); | |
$zip->close(); | |
echo 'ok'; | |
} else { | |
echo 'failed'; | |
} | |
echo "<hr />\n"; | |
if (isset($removeorig)) { | |
echo "Deleting Zip...<br />\n"; | |
unlink("$file"); | |
} | |
} | |
if (isset($unzipper)) { | |
echo "Deleting Script...<br />\n"; | |
unlink(__FILE__); | |
echo "Script Deleted!<br /><a href=\"/\">HOME</a>\n"; | |
exit; | |
} | |
$handler = opendir("."); | |
echo "Please choose a file to unzip: <br />\n"; | |
echo '<form action="" method="get">'."\n"; | |
$found = 0; | |
while ($file = readdir($handler)) | |
{ | |
if(strrchr($file,".zip") != ".zip" ) { continue; } | |
{ | |
echo '<input type="radio" name="file" value="' . $file . '"/> ' . $file . "<br />\n"; | |
$found = 1; | |
} | |
} | |
echo '<hr/><input type="checkbox" name="removeorig" value="Remove" />Delete .zip after extraction?'."<br />\n"; | |
echo '<input type="checkbox" name="unzipper" value="Remove" />Delete Unzipper Script? (Uncheck this box if you have more files to unzip!)'."<br />\n"; | |
closedir($handler); | |
if ($found == FALSE) | |
echo "No .zips found<br />"; | |
else | |
echo '<br />NOTE: This unzips and <strong>REPLACES</strong> files.<br /><br /><input type="submit" value="Unzip!" />'; | |
echo "\n</form>"; | |
?> | |
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment