0

I fail to understand why when I upload images larger than 2M they enter the server as usual while those that are larger than 100kb and less than 2M do not enter at the same time they enter less than 100kb. How can I only allow less than 100kb to be uploaded to a server

//My image array
$allowed = array('png', 'PNG');
//validate
if (in_array(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION), $allowed) &&   ($_FILES['image']['size'] > 102400)) {
    $errors['image'] = "image greater than 100kb not allowed!";
}
//my php.ini
upload_max_filesize=2M
post_max_size=8M

EDIT: it work after changing the upload_max_filesize=0.1M as 100kb and post_max_size=30000M it validate all files, but when user upload more 100M file it take a time to display error message, how to solve it

$type = array('png', 'jpg');
if(!empty($_FILES['image']['tmp_name']) && !in_array(pathinfo($_FILES['image']['tmp_name'], PATHINFO_EXTENSION), $type)) {
    $errors['type'] = 'only png or jpg is allowed!';
}

1 Answers1

0

Try to use filesize function before

$file_tmp = $_FILES['image']['tmp_name'];
$size = filesize($file_tmp);