Hello I have a validation check for my form which is checking the images existing, count and
size in a IF condition but in here the image size validation is not working.
In my code I have defined that users can only upload up to 500 KB six images size but here I am
unable to upload six images which total all of them are only 340 KB.
Here is the Code:
$maxsize = '500000'; //Bytes
$errors = array();
if (empty($_FILES['Upload_Property_Images']['name'][0]))
{
$errors[] = 'You have not selected any image for uplaod field';
}
elseif ($_FILES['Upload_Property_Images']['size'] > $maxsize )
{
$errors[] = 'All six images must be less than 500 KB size';
}
else
{
if (count($_FILES['Upload_Property_Images']['name']) !== 6)
$errors[] = "-Your Only Allowed Six Images";
$whitelist = array("jpg","png","JPG","PNG");
foreach($_FILES['Upload_Property_Images']['name'] as $file)
{
if ($file)
{
$temp = explode('.', $file);
if (!in_array(end($temp), $whitelist ))
{
$errors[] = "-All images must be JPG or PNG<br>";
break;
}
}
}
}