I've set up a form that you can add an image from a local machine, and it will upload it to my server replacing the filepath. That works, it also checks to see if the image has already been placed in the final directory destination, if it has it will reject the upload.
I want to validate the width and height of the image before the upload, if it is bigger than the $image_max_width or $image_max_height then it needs to reject the upload.
However it keeps on accepting the upload, replacing the image filepath with a tmp/ directory, not uploading the desired image, and when I do a select all images within the db it shows as missing.
The code I'm using is:
$allowed_types = $allowed_images;
$str = validate_upload($n_pic,$n_pic_type,$n_pic_size,$n_pic_name,$max_image_size);
if (!$str)
{
//Check file does not exist
$new_name = "../images/competitions/popup/" .
$n_pic_name;
if (file_exists($new_name))
{
echo "<P CLASS='mainAlert'>The image ($n_pic_name) already exists! Please rename the file on your hard drive, and then try to upload it again.</P>";
$doInsert=false;
}
else
if (@copy ($n_pic,"../images/competitions/popup/".$n_pic_name))
{
$n_pic = "images/competitions/popup/" . $n_pic_name;
$doInsert=true;
}
// Code not working
if (ereg("image",$n_pic_type) && (in_array($n_pic_type,$allowed_types)))
{
$image_info = getimagesize($n_pic_file);
if ($image_info[0] > $image_max_width)
echo "Warning The image should be no wider than " . $image_max_width . " pixels, it is " . $image_info[0]. " pixels wide.<BR>";
if ($image_info[1] > $image_max_height)
echo "Warning The image should be no higher than " . $image_max_height . " pixels, it is " . $image_info[1]. " pixels high.<BR>";
$doInsert=false;
}
} // Valid file
Also it returns an error msg, relating to the ($image_info = getimagesize($n_pic_file)😉 line, when I upload a file that has the correct width and height.
Can I only use - $image_info = getimagesize($n_pic_file); if I have already entered the image into a db and am doing a select?
Any help would be great!!