<?php

include 'db.php';
include 'error.php';
include 'auth.php';

$tmpfile=$_FILES['userfile']['tmp_name'];
$tmpname=$_FILES['userfile']['name'];
//error_reporting(0);
list($width, $height, $type, $attr) = getimagesize($tmpfile);
$maxwidth=410;


if (is_uploaded_file($tmpfile)==FALSE || $width>$maxwidth)
{


	include 'header.php';
	?>

		<span class="head0">Admin - Upload Image</span><p>
		<form enctype="multipart/form-data" action="admin_upload.php" method="POST">
		<input type="hidden" name="MAX_FILE_SIZE" value="50000">
		Upload file: <input name="userfile" type="file"><p align="center">
		<input type="submit" value="Send File">
		</form>
		
	<?php
	if($_FILES['userfile']['error']!=0)
	{
		echo 'There has been an error.<br>Check the file is smaller than 50k in size.';
	}
	if($width>$maxwidth)
	{
		echo 'The image width is too large, please reduce then retry.';
	}



	include 'footer.php';

}else
{

	$uploaddir = $_SERVER['DOCUMENT_ROOT']."/uploads/";
	$uploadfile = $uploaddir. $tmpname;

	if (move_uploaded_file($tmpfile, $uploadfile)) {
		$success=1;
	} else {
		$success=0;
	}
	
	include 'header.php';

	echo'<span class="head0">Admin - Upload Image</span><p>';
	if($success==1)
	{
		echo'Successfully uploaded image as follows:<p align="center">';
		echo'<img src="uploads/'.$tmpname.'" border="0" hspace="0" vspace="0"';
	}else{
		echo'Image upload unsuccessful.';
	}
	include 'footer.php';




}
?>