All pastes #989230 Raw Edit

Unnamed

public text v1 · immutable
#989230 ·published 2008-04-18 07:10 UTC
rendered paste body
<?php
	$max_filesize = 3 * 1024 * 1024;
	$allowed_extensions = array ("jpeg", "doc", "pdf", "xls");
	
	//print_r($_SERVER);
	for ($i = 0; $i < 4; $i++)
	{
		//error == 4 means the user is trying to upload an empty field.
		if ($_FILES['file'.$i]['error'] == 4) {
			echo "Skipping file #", $i, ", because it's empty";
			continue;
		}
		else {
			//storing filesize
			$filesize = $_FILES['file'.$i]['size'];
			
			//getting the filename and the extension.
			list ($filename, $extension) = explode(".", $_FILES['file'.$i]['name']);
			
			if ($filesize > $max_filesize) {
				echo "The file size is way too big, skipping file #", $i;
				continue;
			}
			else {
				if (strcmp($extension, $allowed_extensions[$i]) != 0) {
					echo "File extension is invalid, skipping file #", $i;
					continue;
				}
				else {
					echo dirname($_SERVER['PHP_SELF'])."/". $filename;
					
					if(mkdir (dirname($_SERVER['PHP_SELF'])."/". $filename, 0700, TRUE))
						echo "Succefull";
					else
						echo "failed";
				}
		 	}#endif
		}#end if
	}#end forloop.
?>