简体   繁体   中英

Issue with getimagesize() warning, when a large file is uploaded

I have a wee problem here. This is part of a string of code that validates an image file before it's uploaded.

//Check if the image is real or fake (fyi 1 is good 0 is not good)
if($uploadOK){
    $check = getimagesize($_FILES["banner_708"]["tmp_name"]);
    if($check !== false || !empty($check)) {
        $uploadOK = 1;
    } 
    else {
        $uploadOK = 0;
        array_push($banner_msg_array, "This is not a valid image.");
    }
}

The problem is when a file is too large. What ends up happening in the above code is getimagesize() evaluates to empty. Then I get my own array_push message in the else statement, but also a system error:

Warning: getimagesize(): Filename cannot be empty in

I thought that the above logic if($check !== false || !empty($check)) would eliminate this error; if it's false or empty, then go to else and push the array. It sort of does, but why the system error? How can I get rid of this?

I do have the overall code checking for file size, but it doesn't matter in what order I place it, before or after the above code, I still get this system warning when a file is too large, and I think it's because getimagesize() has nothing to evaluate. The problem is what can be changed to eliminate this?

Any help would be appreciated.

Check whether the file was received correctly.

if ($_FILES["banner_708"]["error"]){
    $uploadOK = 0;
    $banner_msg_array[] = "Image could not be uploaded";
} else {
    $check = getimagesize($_FILES["banner_708"]["tmp_name"]);
    if($check !== false || !empty($check)) {
        $uploadOK = 1;
    } 
    else {
        $uploadOK = 0;
        array_push($banner_msg_array, "This is not a valid image.");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM