<?php

$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$userId = $_POST["userId"];

$target_dir = "http://cgi.soic.indiana.ed/~team3/user_images";

if (!file_exists($target_dir))
{
mkdir($target_dir, 0777, true);
}

$target_dir = $target_dir . "/" . basename($_FILES["file"]["name"]);

// attempt *
$messageSuccess = array(
"Message" => "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.",
"Status" => "OK",
"userId" => $_REQUEST["userId"]
);
// attempt *
$messageFail = array(
"Message" => "Sorry, there was an error uploading your file.",
"Status" => "Error",
"userId" => $_REQUEST["userId"]);

// if file was uploaded,
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_dir)) {
echo json_encode($messageSuccess);
// if file was not uploaded,
} else {

echo json_encode($messageFail);
}

?>
