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
Code: Select all
<?php
if($_FILES['userfile']['size'] > 1) {
// set some variables for the maximum parameters
$max_size = 700000;
$max_height = 800;
$max_width = 800;
// get information on the file that was uploaded
// get filesize
$info = getimagesize($_FILES['userfile']['tmp_name']);
// filter through limitations set earlier
//check file-size (in bytes):
if(($_FILES['userfile']['size'] > $_POST['MAX_UPLOAD_SIZE']) || ($_FILES['userfile']['size'] > $max_size)) {
$error_size = 1;
echo "<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> you";
die("<BR><BR>Error: Upload file size too large: (<b>" . $_FILES['userfile']['size'] . "</b>). Must not exceed ".$max_size."kb.");
unset ($_FILES);
}
//check the extension.
$array = explode(".", $_FILES['userfile']['name']);
$nr = count($array);
$ext = $array[$nr-1];
if(($ext !="jpg") && ($ext !="jpeg") && ($ext !="png") && ($ext !="pjpeg")) {
$error_ext = 1;
die("<BR><BR>Error: file extension un-recognized. Be sure your image follows the correct extension (.JPG or .PNG)");
unset ($_FILES);
}
//CHECK TYPE: (what the browser sent)
if(($_FILES['userfile']['type'] != "image/jpeg") && ($_FILES['userfile']['type'] != "image/pjpeg") && ($_FILES['userfile']['type'] != "image/png")) {
$error_extension = 1;
die("<BR><BR>Error: Upload file type un-recognized. Only .JPG or .PNG images allowed.");
unset ($_FILES);
}
//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize() -In case it was a FAKE!
if(($info['mime'] != "image/jpeg") && ($info['mime'] != "image/pjpeg") && ($info['mime'] != "image/png")) {
$error_extension2 = 1;
die("<BR><BR>Error: Upload file type un-recognized. Only .JPG or .PNG images allowed.");
unset ($_FILES);
}
//check file size (length & width)
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 .".");
unset ($_FILES);
}
//check if a file was loaded
if ($_FILES['userfile'] == NULL) {
echo "You didn't upload anything";
die("Your upload was empty");
}