<?php

$image = $_POST["image"];
$counter = $_POST["counter"];
$username = $_POST["userName"];
$userpass = $_POST["userPass"];
$target_dir = "../datBundle/".$username."/dashCam/";

/*
if(!file_exists($target_dir)) {
    echo "folder does not exists";
    mkdir($target_dir,0777, true);
} else {
    echo "folder exists";
}
*/


$target_dir = $target_dir.time().".jpeg";
if(file_put_contents($target_dir, base64_decode($image))) {
    //used for changing image permission, but after mozilla can't display the image
    //chmod($target_dir, 0751);

    echo json_encode([
        "Message" => "File has been uploaded",
        "Status" => "OK"
    ]);
} else {
    echo json_encode([
        "Message" => "Sorry, there has been an error uploadinf your file",
        "Status" => "Error"
    ]);
}

?>