Check if specific input file is empty

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

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





        
相关标签:
11条回答
  • 2020-11-29 07:35
     if( ($_POST) && (!empty($_POST['cover_image'])) )    //verifies  if post exists and cover_image is not empty
        {
        //execute whatever code you want
        }
    
    0 讨论(0)
  • 2020-11-29 07:38
    if(!empty($_FILES)) { // code if not uploaded } else { // code if uploaded }
    
    0 讨论(0)
  • 2020-11-29 07:39
    if (empty($_FILES['cover_image']['name']))
    
    0 讨论(0)
  • 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)

    0 讨论(0)
  • 2020-11-29 07:48

    You can check if there is a value, and if the image is valid by doing the following:

    if(empty($_FILES['cover_image']['tmp_name']) || !is_uploaded_file($_FILES['cover_image']['tmp_name']))
    {
       // Handle no image here...
    }
    
    0 讨论(0)
  • 2020-11-29 07:48

    simple :

    if($_FILES['cover_image']['error'] > 0)
        // cover_image is empty
    
    0 讨论(0)
提交回复
热议问题