static function DetermineFileType($filename, $options = array(), &$preferred_suffix = null){
		$options += array(
			"original_filename" => null,
		);

		if(!file_exists($filename) || is_dir($filename)){
			return null;
		}
		

		if(function_exists("mime_content_type")){
			$mime_type = mime_content_type($filename);
		}elseif(function_exists("finfo_open")){
			$finfo = finfo_open(FILEINFO_MIME_TYPE);
			$mime_type = finfo_file($finfo, $filename);
		}else{
			$command = "file -i ".escapeshellarg($filename);
			$out = `$command`;
			// /tmp/xxsEEws: text/plain charset=us-ascii
			// -> text/plain
			// ya.gif: image/gif; charset=binary
			// -> image/gif
			if(preg_match("/^.*?:\\s*([^\\s]+\\/[^\\s;]+)/",$out,$matches)){
				$mime_type = $matches[1];
			}else{
				$mime_type = "application/octet-stream";
			}
		}

		$original_filename = $options["original_filename"];
		if(!$original_filename){
			preg_match('/([^\/]+)$/',$filename,$matches); // "/path/to/file.jpg" -> "file.jpg"
			$original_filename = $matches[1];
		}
		$original_suffix = "";
		if(preg_match('/\.([^.]{1,10})$/i',$original_filename,$matches)){
			$original_suffix = strtolower($matches[1]); // "FILE.JPG" -> "jpg"
		}
		$preferred_suffix = $original_suffix;

		$tr_table = array(
			// most desirable suffix is on the first position
			// 										the most desirable type is on the first position
			"xls" =>				array("application/vnd.ms-excel","application/msexcel","application/vnd.ms-office","application/msword"),
			"xlsx" =>				array("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/zip","application/octet-stream"), // !! application/octet-stream seems to be a little odd
			"doc" =>				array("application/msword","application/vnd.ms-office"),
			"ppt" =>				array("application/vnd.ms-powerpoint","application/vnd.ms-office","application/msword"),
			"jpg|jpeg" =>		array("image/jpeg","image/jpg"),
			"svg" =>				array("image/svg+xml","image/svg","text/plain"),
			"bmp" =>				array("image/bmp","image/x-bmp","image/x-ms-bmp","application/octet-stream"),
			"eps" =>				array("application/postscript","application/eps"),
			"csv" =>				array("text/csv","text/plain"),
			"docx" => 			array("application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/zip"),
		);

		foreach($tr_table as $suffixes => $mime_types){
			$suffixes = explode("|",$suffixes);
			if(in_array($original_suffix,$suffixes) && in_array($mime_type,$mime_types)){
				$mime_type = $mime_types[0];
				$preferred_suffix = $suffixes[0];
				break;
			}
		}
		
		return $mime_type;
	}