<?php 
$baseURL = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
$servername = "db02.noc24online.net"; 
$username = "gyxbqlbq_ehospital20202";  
$password = "ehospital2020";  
$dbname = "gyxbqlbq_eHospital";
$conn = new mysqli($servername, $username, $password, $dbname);

	
	
	//creating the upload url 
	$upload_url = $baseURL . '/eHospital/uploads/'; 

	//response array 
	$response = array(); 
	
	if($_SERVER['REQUEST_METHOD']=='POST'){
		
		if(isset($_FILES['image']['name'])){
			

			$fileinfo = pathinfo($_FILES['image']['name']);
			
			$fileName = $fileinfo['filename'];;
			
			$extension = $fileinfo['extension'];
			
			$upload_destination = './uploads/'.$_FILES['image']['name'];
			

			$file_path = $upload_url . $_FILES['image']['name']; 
			
			try{
				//saving the file 
				move_uploaded_file($_FILES['image']['tmp_name'], $upload_destination);
				$sql = "INSERT INTO image (`image`) VALUES ('$file_path')";
				$conn->query($sql);

			}catch(Exception $e){
				$response['error']=true;
				$response['message']=$e->getMessage();
			}		

			echo json_encode($response);

		}else{
			$response['error']=true;
			$response['message']='Please choose a file';
		}
	}