<?php
	// upload.php	this file is part of the
	// Font Lister v0.2 by Tuxman < tuxman@gamersirc.net >
	
	$font_text = $_POST["font_text"];
	$font_size = $_POST["font_size"];
	$nospecial = $_POST["nospecial"];
	
	// security check:
	// if $font_text contains \n characters, the following parameters
	// won't be processed correctly, so we need to replace them!
	// note that nl2br can't be used here as it would use <br /> which
	// will also fail due to the slash...
	$font_text = str_replace("\n", "<br>", $font_text);
	
	if (isset($_FILES["fontfile"])) {
		// create random number (unique!)
		$randNumber = md5(uniqid(rand(), TRUE));
		
		// upload file ... using code found at selfphp.de, (c) :-)
		if ($_FILES["fontfile"]["error"] == UPLOAD_ERR_OK) {
			$regExp = "/^[a-z_]([a-z0-9_-]*\.?[a-z0-9_-])*\.[a-z]{3,4}$/i";
			if (preg_match($regExp,$_FILES["fontfile"]["name"]) && $_FILES["fontfile"]["size"] > 0 && $_FILES["fontfile"]["size"] < 100000) {
				move_uploaded_file($_FILES["fontfile"]["tmp_name"],"files/" . $randNumber);
				header("Location: index.php?action=success&fileid=" . $randNumber . "&text=" . $font_text . "&size=" . $font_size . "&nospecial=" . $nospecial);
			}
			else
				header("Location: index.php?action=error&error=too_large");
		}
		else
			header("Location: index.php?action=error&error=transfer");
	}
	else
		header("Location: index.php?action=error&error=failed");
?>