<?php
	$fn = $_REQUEST['n'] ;
	$docUploaded = false ;
	$limitsize = 5000 * 1024;	//5mb
	if (!empty($_FILES)) {
		$size = $_FILES[$fn]['size'];
		if($size > 0){
			if ($size < $limitsize) {
				$docfile =  basename($_FILES[$fn]['name']);
				$pi = pathinfo($docfile);
				$ext = $pi['extension'];
				$exts = array("png","jpg","jpeg", "pdf","doc","docx", "xls","xlsx");
				if (Util::validFileExt($ext,$exts)) {
					$tmpfile = md5($docfile . time()) . "." . $ext ;
					if(!file_exists(PATH_TEMP)) mkdir(PATH_TEMP) ;
					$uploadfile = PATH_TEMP . $tmpfile ;
					// log::write($uploadfile);
					if (move_uploaded_file($_FILES[$fn]['tmp_name'], $uploadfile)) {
						$docUploaded = true ;
						$err = "" ;
					} else {
						$err = "Error in processing uploaded file." ;
					}
				} else {
					$err = "Unsupported upload file type." ;
				}
			} else {
				$err = "Upload file over limit. Upload file size must be less than 50KB." ;
			}
		} else {
			$err = "Missing upload file.";
		}
	} else {
		$err = "No upload file found." ;
	}
	if($docUploaded){
		echo Status::Ok . "|" . $docfile . "|" . $tmpfile;
	}else{
		echo Status::Error . "|" . $err ;
	}
	
?>