<?php 
//mysql server
    $dbserver = "localhost";
    $dbuser = "root";
    $dbpass = "Gold@53743001";
    $dbname = "app";

    foreach($_POST as $key => $value){
        $$key = $value;
	}
    $time = date('Y-m-d-H-i-s',time());
    $imgName = date('Y_m_d_H_i_s',time()).".jpg";
    $target_dir = 'uploads/';

    $data = file_get_contents('php://input');
    if(!(file_put_contents($target_dir . $imgName,$data)=== FALSE)){
        $con =mysqli_connect($dbserver,$dbuser,$dbpass,$dbname);
        $sql = "INSERT INTO `image` (`img`,`datetime`) VALUES('$imgName','$time')";
        mysqli_query($con,$sql) or die(mysqli_error(). "<hr/>Line:".__LINE__."br/>$sql");

        mysqli_close($con);
        echo 'OK';

    }else echo 'failed';
?>
