Skip to content

Commit

Permalink
Added zip and tar upload and download functionallity
Browse files Browse the repository at this point in the history
  • Loading branch information
yamikaitou committed Jun 29, 2011
1 parent 94edf36 commit 69a96a3
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 15 deletions.
2 changes: 1 addition & 1 deletion SQLiteSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
52 changes: 44 additions & 8 deletions amxmodx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]."<br>";
$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]."<br>";
}
}
}
}
else
{
Expand Down
56 changes: 50 additions & 6 deletions download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}


Expand All @@ -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);
Expand Down

0 comments on commit 69a96a3

Please sign in to comment.