Created
December 6, 2013 01:37
-
-
Save hideki-a/7817239 to your computer and use it in GitHub Desktop.
共用サーバー上で、MTやa-blog cms等のCMSのzipファイルを解凍するツール。CMSのzipと共にアップし、このPHPにアクセスすればOK。
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 | |
/* | |
* Unzip Tool | |
* Unzip files on shared server. | |
* | |
* The MIT License (MIT) | |
* | |
* Copyright (c) 2013 Hideki Abe | |
*/ | |
function getFileNames() | |
{ | |
$list = `ls`; | |
return explode("\n", trim($list)); | |
} | |
function unzipFile($filename) | |
{ | |
$result = shell_exec('unzip ' . $filename); | |
return $result; | |
} | |
header('Content-type: text/html; charset=UTF-8'); | |
if ($_POST['mode'] == 'unzip') | |
{ | |
$scriptName = $_SERVER['SCRIPT_NAME']; | |
$filename = $_POST['filename']; | |
$result = unzipFile($filename); | |
$html = "<p>{$filename}のunzip結果は下記の通りです。</p>\n"; | |
$html .= "<textarea cols='80' rows='20'>{$result}</textarea>\n"; | |
$html .= "<p><a href='{$scriptName}'>最初の画面に戻る</a></p>"; | |
echo $html; | |
} | |
else | |
{ | |
$scriptName = $_SERVER['SCRIPT_NAME']; | |
$arrFiles = getFileNames(); | |
$nLoop = 0; | |
$html = "<p>解凍するファイルを選んで下さい。</p>\n<form action='{$scriptName}' method='post'>\n<ul>"; | |
foreach ($arrFiles as $file) { | |
if (strpos($file, '.zip') <= 0) continue; | |
$html .= "<li><input type='radio' name='filename' value='{$file}' id='r{$nLoop}'> <label for='r{$nLoop}'>{$file}</label></li>\n"; | |
$nLoop += 1; | |
} | |
$html .= "</ul>\n<input type='hidden' name='mode' value='unzip'><input type='submit' value='解凍'>\n</form>"; | |
echo $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment