From 69a96a311f3734d215399c67e7191c4852c97c1d Mon Sep 17 00:00:00 2001 From: Ryan LeBlanc Date: Wed, 29 Jun 2011 06:37:52 -0500 Subject: [PATCH] Added zip and tar upload and download functionallity --- SQLiteSetup.php | 2 +- amxmodx.php | 52 ++++++++++++++++++++++++++++++++++++++------- download.php | 56 +++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 95 insertions(+), 15 deletions(-) diff --git a/SQLiteSetup.php b/SQLiteSetup.php index 9450a65..677a54e 100644 --- a/SQLiteSetup.php +++ b/SQLiteSetup.php @@ -17,7 +17,7 @@ sqlite_exec($sql, "INSERT INTO info VALUES(5, 'TempUpload', '.');"); sqlite_exec($sql, "INSERT INTO info VALUES(6, 'vBUpload', '.');"); sqlite_exec($sql, "INSERT INTO info VALUES(7, 'IPBUpload', '.');"); -sqlite_exec($sql, "CREATE TABLE compile (ID INTEGER, Program TEXT, Version TEXT)"); +sqlite_exec($sql, "CREATE TABLE compile (ID INTEGER, Program TEXT, Version TEXT, Type TEXT)"); sqlite_exec($sql, "CREATE TABLE stats (ID INTEGER, Value1 TEXT, Value2 TEXT)"); sqlite_close($sql); diff --git a/amxmodx.php b/amxmodx.php index ab3aac5..f1e8d07 100644 --- a/amxmodx.php +++ b/amxmodx.php @@ -43,17 +43,43 @@ if ($_POST['boxcode'] != "") { file_put_contents($info[4]['Value']."/$rand/".$_POST['boxname'].".sma", stripslashes($_POST['boxcode'])); - $file = $_POST['boxname'].".sma"; } else { - if (pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION) == "sma") - move_uploaded_file($_FILES['file']['tmp_name'], $info[4]['Value']."/$rand/".$_FILES['file']['name']); + switch (pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION)) + { + case "sma": + { + move_uploaded_file($_FILES['file']['tmp_name'], $info[4]['Value']."/$rand/".$_FILES['file']['name']); + break; + } + case "zip": + { + $zip = new ZipArchive; + $res = $zip->open($_FILES['file']['tmp_name']); + if ($res === TRUE) + { + $zip->extractTo($info[4]['Value']."/$rand"); + $zip->close(); + } + break; + } + case "gz": + { + move_uploaded_file($_FILES['file']['tmp_name'], $info[4]['Value']."/$rand/".$_FILES['file']['name']); + exec("cd {$info[4]['Value']}/$rand; tar xvfz ".$_FILES['file']['name']); + unlink($info[4]['Value']."/$rand/".$_FILES['file']['name']); + break; + } + } + + - $file = $_FILES['file']['name']; } - sqlite_exec($sql, "INSERT INTO compile VALUES('$rand', 'amxx', '{$_POST['ver']}');"); + + + sqlite_exec($sql, "INSERT INTO compile VALUES('$rand', 'amxx', '{$_POST['ver']}', '".pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION)."');"); $curl = curl_init("http://".$_SERVER["SERVER_NAME"].pathinfo($_SERVER["REQUEST_URI"], PATHINFO_DIRNAME)."/compile.php?id=$rand"); curl_exec($curl); @@ -75,9 +101,19 @@ } - $fail = explode("\n", file_get_contents($info[3]['Value']."/$rand/".pathinfo($file, PATHINFO_FILENAME).".txt")); - for ($k = 0; $k < sizeof($fail); $k++) - echo $fail[$k]."
"; + $files = scandir($info[3]['Value']."/$rand"); + foreach ($files as $object) + { + if ($object != "." && $object != "..") + { + if (pathinfo($info[3]['Value']."/$rand/".$object, PATHINFO_EXTENSION) == "txt") + { + $fail = explode("\n", file_get_contents($info[3]['Value']."/$rand/$object")); + for ($k = 0; $k < sizeof($fail); $k++) + echo $fail[$k]."
"; + } + } + } } else { diff --git a/download.php b/download.php index 996e181..b44a4e5 100644 --- a/download.php +++ b/download.php @@ -19,9 +19,53 @@ $files = scandir($info[3]['Value']."/$id"); -if (count($files) == 4) +foreach ($files as $object) { - $file = $files[2]; + if ($object != "." && $object != "..") + { + if (pathinfo($info[3]['Value']."/$id/".$object, PATHINFO_EXTENSION) == "amxx" OR pathinfo($info[3]['Value']."/$id/".$object, PATHINFO_EXTENSION) == "smx") + { + $file[] = $object; + } + } +} + +if (count($file) == 1) +{ + $filename = $file[0]; +} +else +{ + switch ($compile['Type']) + { + case "zip": + { + $count = 0; + $zip = new ZipArchive; + $res = $zip->open($info[3]['Value']."/$id/$id.zip", ZIPARCHIVE::OVERWRITE); + if ($res === TRUE) + { + while (count($file) > $count) + $zip->addFile($info[3]['Value']."/$id/".$file[$count], $file[$count++]); + + $zip->close(); + } + + $filename = "$id.zip"; + break; + } + case "gz": + { + $count = 0; + $filelist = ""; + while (count($file) > $count) + $filelist .= $file[$count++]." "; + + exec("cd {$info[3]['Value']}/$id; tar cvzf $id.tar.gz $filelist"); + $filename = "$id.tar.gz"; + break; + } + } } @@ -37,12 +81,12 @@ @ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); header("Content-Transfer-Encoding: none"); -header("Content-Type: $mimetype; name=\"$file\""); -header("Content-Disposition: inline; filename=\"$file\""); -$size = @filesize($info[3]['Value']."/$id/$file"); +header("Content-Type: $mimetype; name=\"$filename\""); +header("Content-Disposition: inline; filename=\"$filename\""); +$size = @filesize($info[3]['Value']."/$id/$filename"); if ($size) header("Content-length: $size"); -readfile($info[3]['Value']."/$id/$file"); +readfile($info[3]['Value']."/$id/$filename"); sqlite_close($sql);