<?php

/*Import File Directory*/
$target_dir = "excel-import/";

if(is_array($_FILES)) {
	if(is_uploaded_file($_FILES['FileName']['tmp_name'])) {

		$sourcePath = $_FILES['FileName']['tmp_name'];
		$targetPath = $target_dir.$_FILES['FileName']['name'];
		$FileName = $_FILES['FileName']['name'];
		$FileSize = $_FILES['FileName']['size'];
		
		//get file extension
		$Filetype = strtolower(pathinfo($FileName, PATHINFO_EXTENSION));
		
		if (file_exists($targetPath)) {
			unlink($targetPath);		
		}
		
		//The file Check extension
		if (($Filetype == 'xlsx') || ($Filetype == 'xls') || ($Filetype == 'xltx') || ($Filetype == 'csv') || ($Filetype == 'CSV')) {
			if(move_uploaded_file($sourcePath,$targetPath)) {
				
				$msgList["msgType"] = 'success';
				$msgList['msg'] = 'The file '.$FileName.' has been uploaded';
				$msgList["FileName"] = $FileName;
				
			} else {
				$msgList["msgType"] = 'error';
				$msgList['msg'] = '<span class="red">Sorry, there was an error uploading your file.</span>';
				$msgList["FileName"] = '';
			}
		} else {
			$msgList["msgType"] = 'error';
			$msgList['msg'] = '<span class="red">Sorry, only excel/csv file are allowed.</span>';
			$msgList["FileName"] = '';
		}
		
	}else{
		$msgList["msgType"] = 'error';
		$msgList['msg'] = '<span class="red">Sorry, there was an error uploading your file.</span>';
		$msgList["FileName"] = '';
	}
}

echo json_encode($msgList);

?>