<?php 
$baseURL = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];

$servername = "db02.noc24online.net"; 
$username = "gyxbqlbq_pcdnf2k";  
$password = "UEROY20scHeJ";  
$dbname = "gyxbqlbq_pcdnfma";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

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

	//response array 
	$response = array(); 
	file_uploads = On
	
	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_uploads (`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';
		}
	}
	
