<?php
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Wed, 09 Sep 2009 09:09:09 GMT');
?><!DOCTYPE html><html><head>
	<meta charset="utf-8" />
	<title>upper</title>
	<meta name="viewport" content="width:device-width, initial-scale=1" />
	<style>
input {
	display: block;
}
</style></head><body>
	<h1>okay fine i'll add a fucking description jesus christ</h1>
	<p>put files into the boxes below</p>
	<p>any boxes are fine, any order is fine, any number is fine</p>
	<p>press any of the submit buttons, any button is fine</p>
	<h1>there was that so goddamn hard</h1>
	<h1>fuck</h1>
	<form method="post" enctype="multipart/form-data">
		<input type="submit" name="submit" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="file" name="f[]" />
		<input type="submit" name="submit" />
		<textarea name="tx"></textarea>
	</form>
<?php
	if (isset($_POST) && isset($_POST['tx']))
	{
		$td = time();
		$tx = $_POST['tx'];
		if (strlen($tx) > 0)
		{
			file_put_contents("inc/$td.txt",$_POST['tx']);
		}
	}
	if (isset($_FILES) && isset($_FILES['f']))
	{
		if (!isset($_FILES['f']['name']) ||
			!isset($_FILES['f']['name'][0]))
		{
			die('filename not set (what tue fuck)');
		}
		$fd = array();
		$fc = count($_FILES['f']['name']);
		$fk = array_keys($_FILES['f']);
		for ($i = 0; $i < $fc; $i++)
		{
			foreach ($fk as $k)
			{
				$fd[$i][$k] = $_FILES['f'][$k][$i];
			}
		}
		foreach ($fd as $f)
		{
			if ($f['error'] > 0)
			{
				echo ('error: ' + $f['error'] .'<br />');
				continue;
			}
			//print_r($f);
			$fn = $f['name'];
			$fn = preg_replace('/[^a-zA-Z0-9]/', '_', $fn);
			if (strlen($fn) > 1)
			{
				$fn = "inc/$fn";
				$ofs = strrpos($fn, '_');
				if ($ofs > 0 && $ofs < strlen($fn))
				{
					$ext = strtolower(substr($fn, $ofs + 1));
					if ($ext == "jpg" ||
						$ext == "png" ||
						$ext == "gif" ||
						$ext == "txt" ||
						$ext == "exe" ||
						$ext == "mp3" ||
						$ext == "flac" ||
						$ext == "ogg" ||
						$ext == "zip" ||
						$ext == "7z" ||
						$ext == "rar" ||
						$ext == "tgz")
					{
						$fn = substr($fn, 0, $ofs) .'.'. substr($fn, $ofs + 1);
					}
				}
				move_uploaded_file($f['tmp_name'],  $fn);
				echo ('file saved successfully' .'<br />');
			}
			else
			echo ('bad filename or other error' .'<br />');
		}
	}
	echo 'private file uploader';
?>
</body></html>
