<?php
	$fn = $_REQUEST['n'] ;
	$idx = 0;
	if(isset($_REQUEST['idx'])) {
		$idx = $_REQUEST['idx'] ;
	}
	$docUploaded = false ;
	$limitsize = 5000 * 1024;	//5mb
	// log::write(print_r($_FILES,true));
	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") ;
				if (Util::validFileExt($ext,$exts)) {
					$tmpfile = md5($docfile . time()) . "." . $ext ;
					$uploadfile = PATH_TEMP . $tmpfile ;
					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 . "|" . $uploadfile . "|" . $idx;
	}else{
		echo Status::Error . "|" . $err ;
	}
	
?>