<?php 
//require("functions.php");
$targetFolder = ($_REQUEST['target'] == "btn")?"btn":"image";
$target_dir = "../promos/$targetFolder/";
if($_REQUEST['target'] == "btn"){
	$fileIndex	= "BillboardButtonImage";
}elseif($_REQUEST['target'] == "image"){
	$fileIndex	= "BillboardImage";
}elseif($_REQUEST['target'] == "pdf"){
	$fileIndex	= "BillboardPDF";
}elseif($_REQUEST['targer'] == "slideshow"){
	$fileIndex = "BillboardSlideshow";
}

$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" && strtolower($imageFileType) != "zip") {
	$data['error'] = "This image is not valid, at least does not have the .jpg, .png, .pdf, or .zip 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.";
	    }
}

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

echo json_encode($data);

?>