<?php header("Content-Type: text/plain"); ?>
<?php
	$text_file = "/home/profs/becker/www/461/Asst/DataCompression/Resources/compress.txt";
	$file_maxsize = "5242880";
	$names = array("crmin", "crmax", "crave", "smin", "smax", "save", "dmin", "dmax", "dave");
	umask(0022);
	function pretty_string($name, $length="10")
	{
		global $HTTP_POST_VARS;
		if (empty($HTTP_POST_VARS[$name]))
		{
			$value = "not set";
		}
		else
		{
			$value = substr(strip_tags(rtrim(ltrim($HTTP_POST_VARS[$name]))), 0, $length);
		}
		//$value = strtr($value, '"', '*');
		return ('"' . $value . '"');
	}
	if (filesize($text_file) > $file_maxsize)
	{
		print("The data file is to big to add anymore data.\nSorry!\n");
	} 
	else
	{
		$ofile = fopen($text_file,"a");
		flock($ofile, LOCK_EX);
		fwrite($ofile, pretty_string("uname1", 30). " ");
		fwrite($ofile, pretty_string("uname2", 30). " ");
		fwrite($ofile, pretty_string("algo", 30). " ");
		for ($i = 1; $i <= 4; $i++)
		{
			foreach($names as $name)
			{
				fwrite($ofile, pretty_string($name.$i). " ");
			}
		}
		fwrite($ofile, "\n");
		flock($ofile, LOCK_UN);
		fclose($ofile);
	}
	readfile($text_file);
?>
