Check if specific input file is empty

后端 未结 11 708
醉酒成梦
醉酒成梦 2020-11-29 07:23

In my form I have 3 input fields for file upload:





        
11条回答
  •  一整个雨季
    2020-11-29 07:44

    You can check by using the size field on the $_FILES array like so:

    if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
    {
        // cover_image is empty (and not an error)
    }
    

    (I also check error here because it may be 0 if something went wrong. I wouldn't use name for this check since that can be overridden)

提交回复
热议问题