<?php
include('../db.php');


// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip', 'txt');

if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){

	$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);

	if(!in_array(strtolower($extension), $allowed)){
		echo '{"status":"error"}';
		exit;
	}
	
$name = $_POST['name'];
$fname = $_POST['fname'];
$phone = $_POST['phone'];
$uid = $_POST['uid'];

if(file_exists('../files/empuploads/'.$uid) && is_dir('../files/empuploads/'.$uid))
{
$path = '../files/empuploads/'.$uid.'/'.$_FILES['upl']['name'];
}
else
{
mkdir('../files/empuploads/'.$uid);
$path = '../files/empuploads/'.$uid.'/'.$_FILES['upl']['name'];
}

	if(move_uploaded_file($_FILES['upl']['tmp_name'], $path))
	{
		$q = "insert into docuploads(uid,name,fname,phone,path,type) values('$uid','$name','$fname','$phone','$path','employee')";
		mysqli_query($dbcon,$q) or die(mysqli_error($dbcon));
		echo '{"status":"success"}';
		exit;
	}
}

echo '{"status":"error"}';
exit;