<?php
	include 'AdminRedirect.php';
	
	$UploadOk = 1;
	
	if (isset($_POST['SlideShowUploadSubmit'])) {
		$target_dir = "../Pictures/SlideShow/";
		$target_file = $target_dir . basename($_FILES['FileToUpload']['name']);
		$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
		$check = getimagesize($_FILES['FileToUpload']['tmp_name']);
		
		if ($check !== false) {
			$UploadOk = 1;
		}
		else {
			echo ("<script>alert('File is not an image!');</script>");
			$UploadOk = 0;
		}
		
		//Check if the file already exists
		if (file_exists($target_file)) {
			echo ("<script>alert('File already exists');</script>");
			$UploadOk = 0;
		}
		
		//Check file size
		if ($_FILES['FileToUpload']['size'] > 50000000) {
			echo ("<script>alert('File is too large');<script>");
			$UploadOk = 0;
		}
		
		//Allow certain file formats
		if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "GIF") {
			echo ("<script>alert('Only JPG, JPEG, PNG & GIF files are allowed');</script>");
			$UploadOk = 0;
		}
		
		//Check if UploadOk is set to 0 by error
		if ($UploadOk == 0) {
			echo ("<script>alert('Your file was not uploaded');</script>");
		}
		else {
			if (move_uploaded_file($_FILES['FileToUpload']['tmp_name'], $target_file)) {
				echo ("<script>alert('File ". basename($_FILES['FileToUpload']['name'])." has been uploaded.');</script>");
			}
			else {
				echo ("<script>alert('There was an error uploading file');</script>");
			}
		}
		
		echo ("<script>window.location = 'APhotoManager.php';</script>");
	}
	
	if (isset($_POST['GalleryUploadSubmit'])) {
		$target_dir = "../Pictures/Gallery/";
		$target_file = $target_dir . basename($_FILES['FileToUpload2']['name']);
		$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
		$check = getimagesize($_FILES['FileToUpload2']['tmp_name']);
		
		if ($check !== false) {
			$UploadOk = 1;
		}
		else {
			echo ("<script>alert('File is not an image!');</script>");
			$UploadOk = 0;
		}
		
		//Check if the file already exists
		if (file_exists($target_file)) {
			echo ("<script>alert('File already exists');</script>");
			$UploadOk = 0;
		}
		
		//Check file size
		if ($_FILES['FileToUpload2']['size'] > 50000000) {
			echo ("<script>alert('File is too large');<script>");
			$UploadOk = 0;
		}
		
		//Allow certain file formats
		if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "GIF") {
			echo ("<script>alert('Only JPG, JPEG, PNG & GIF files are allowed');</script>");
			$UploadOk = 0;
		}
		
		//Check if UploadOk is set to 0 by error
		if ($UploadOk == 0) {
			echo ("<script>alert('Your file was not uploaded');</script>");
		}
		else {
			if (move_uploaded_file($_FILES['FileToUpload2']['tmp_name'], $target_file)) {
				echo ("<script>alert('File ". basename($_FILES['FileToUpload2']['name'])." has been uploaded.');</script>");
			}
			else {
				echo ("<script>alert('There was an error uploading file');</script>");
			}
		}
		
		echo ("<script>window.location = 'APhotoManager.php';</script>");
	}
?>