<?php 
//require("functions.php");
$targetFolder = "catalog_buttons";
$target_dir = "../img/$targetFolder/";
	$fileIndex	= "SupplierCatalogButtonImage";


$imageFileType = pathinfo($_FILES[$fileIndex]['name'],PATHINFO_EXTENSION);
$target_file = uniqid(null,true) . "." . $imageFileType;

$uploadOk = 1;


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

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

echo json_encode($data);

?>