HughLa 0 Newbie Poster

ok so basically I have an image uploader in my page and it is giving me troubles

When I first got the script working it had the problem of submitting the same image to mysql whenever the user hit refresh. I fixed this problem with a header that automatically redirected the page after the image was uploaded but now my errors don't show up. this is the upload script that is giving me the headache

if (isset($_POST['submit'])) {
 

// set some variables for the maximum parameters
	$max_size = 700000;
	$max_height = 800;
	$max_width = 800;


$error_message = array();
   
if(($_FILES['userfile']['size'] > $_POST['MAX_UPLOAD_SIZE']) || ($_FILES['userfile']['size'] > $max_size)) {
   $error_message['size'] = "Upload file size too large: (<b>{$_FILES['userfile']['size']}</b>). Must not exceed {$max_size}kb.";
}
      
$array = explode(".", $_FILES['userfile']['name']); 
$nr    = count($array); 
$ext   = $array[$nr-1];
   
// I condensed all 3 of the next if's into one... since they were checking for the same thing pretty much.
if(($ext !="jpg") && ($ext !="jpeg") && ($ext !="png") && 
   ($ext !="pjpeg") && ($_FILES['userfile']['type'] != "image/jpeg") && ($_FILES['userfile']['type'] != "image/pjpeg") && 
   ($_FILES['userfile']['type'] != "image/png") && ($info['mime'] != "image/jpeg") && ($info['mime'] != "image/pjpeg") && 
   ($info['mime'] != "image/png")) {
   $error_message['format'] = "Upload file type un-recognized. Only .JPG or .PNG images allowed.";
}

		$info = getimagesize($_FILES['userfile']['tmp_name']);

	if(($info[0] > $max_width) || ($info[1] >$max_height)) {
	$error_height = 1;
   die("<BR><BR>Error: Image size error (<b>" . $info[0] . "</b> x <b>" . $info[1] . "</b>). Must not exceed ". $max_height . " x ". $max_width .".");
   $error_message['widthnheight'] = "Upload file type un-recognized. Only .JPG or .PNG images allowed.";
	}

if(count($error_message)>0) {
   // we had errors:
   foreach($error_message as $message) {
      echo '<strong>ERROR:</strong> '.$message.'<br>';
   }
   
   die();
   

} else {
   
   // ...

As you can see the first line of code looks for a file submission and, because of my header, this will never evaluate to true.

Once the file is processed the page is automatically redirected so the user will never see the error codes. The images still show up fine in mysql assuming they pass all the requirements in the brackets. I have tried a lot of methods and none has worked. i either get the refresh issue without the header or I get the errors not displaying issue with the header.

Is there a way to display the errors on the redirected page? I tried using sessions to do this and had it working but got errors after a while and the images started playing up.