<?php 
//require("functions.php");
$target_dir = "../img/catalog/";
$imageFileType = pathinfo($_FILES['InventoryItemImageInput']['name'],PATHINFO_EXTENSION);
$target_file = $target_dir . $_POST['Filename'] . "." . "jpg";
$uploadOk = 1;


// Check if image file is a actual image or fake image
if (strtolower($imageFileType) != "jpg" && strtolower($imageFileType) != "png") {
	$data['error'] = "This image is not valid, at least does not have the .jpg or .png extension.";
}else{
	if (move_uploaded_file($_FILES["InventoryItemImageInput"]["tmp_name"], $target_file)) {
	        $data['message'] = "The file ". basename( $_FILES["InventoryItemImageInput"]["name"]). " has been uploaded and renamed to \"" . $_POST['Filename'] . "." . strtolower("jpg") . "\"";
	        $data['url'] = "$target_dir" . $_POST['Filename'] . "." . "jpg";
	        $data['fileuploaded'] = true;
	    } else {
	        $data['error'] = "Sorry, there was an error uploading your file.";
	    }
}

header('Content-Type: application/json');

echo json_encode($data);

?>