title: How can I check that at-least one file is selected for upload
body: <p>how can I check that user has selected at-least one file for upload in below code ?
  i have tried with in_array, isset, !empty functions but no success
  please note that userfile input is array in html</p>
  
  <pre><code>if(!empty($_FILES['userfile']['tmp_name'])){
              $upload_dir = strtolower(trim($_POST['name']));
    // Create directory if it does not exist
                  if(!is_dir("../photoes/". $upload_dir ."/")) {
                       mkdir("../photoes/". $upload_dir ."/");
                  }
              $dirname = "../photoes/".$upload_dir;
  
                      for($i=0; $i &lt; count($_FILES['userfile']['tmp_name']);$i++)
                          {
              // check if there is a file in the array
                           if(!is_uploaded_file($_FILES['userfile']['tmp_name'][$i]))
                              {
                              $messages[] = 'No file selected for no. '.$i.'field';
                              }
              /*** check if the file is less then the max php.ini size ***/
                          if($_FILES['userfile']['size'][$i] &gt; $upload_max)
                               {
                               $messages[] = "File size exceeds $upload_max php.ini limit";
                               }
              // check the file is less than the maximum file size
                          elseif($_FILES['userfile']['size'][$i] &gt; $max_file_size)
                              {
                              $messages[] = "File size exceeds $max_file_size limit";
                              }
                          else
                              {
                  // copy the file to the specified dir 
                              if(@copy($_FILES['userfile']['tmp_name'][$i],$dirname.'/'.$_FILES['userfile']['name'][$i]))
                                  {
                      /*** give praise and thanks to the php gods ***/
                                  $messages[] = $_FILES['userfile']['name'][$i].' uploaded';
                                  }
  
                              }
                          }
                  }else{
                  $messages[] = 'No file selected for upload, Please select atleast one file for upload';
                  dispform();
              }
  </code></pre>