title: multiple image upload validation javascript
body: <p>I used a php code for multiple file upload. It works well. But, when we click the submit button without uploading any file it shows Success &amp; stored in database as value 0. I tried some javascript validation for "Please upload a Image". But still trying... </p>
  
  <p>Anybody can help me..?</p>
  
  <p>Here is the code...</p>
  
  <pre><code>&gt;   &lt;?php
      if(isset($_FILES['files'])){
       $errors= array();
      foreach($_FILES['files']['tmp_name'] as $key =&gt; $tmp_name ){
          $file_name = $key.$_FILES['files']['name'][$key];
          $file_size =$_FILES['files']['size'][$key];
          $file_tmp =$_FILES['files']['tmp_name'][$key];
          $file_type=$_FILES['files']['type'][$key];  
          if($file_size &gt; 2097152){
              $errors[]='File size must be less than 2 MB';
          }
          $query="INSERT into upload_data (`USER_ID`,`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`) VALUES('$user_id','$file_name','$file_size','$file_type'); ";
          $desired_dir="gallery";
          if(empty($errors)==true){
              if(is_dir($desired_dir)==false){
                  mkdir("$desired_dir", 0700);        // Create directory if it does not exist
              }
              if(is_dir("$desired_dir/".$file_name)==false){
                  move_uploaded_file($file_tmp,"gallery/".$file_name);
              }else{                                  //rename the file if another one exist
                  $new_dir="gallery/".$file_name.time();
                   rename($file_tmp,$new_dir) ;               
              }
              mysql_query($query) or die(mysql_error());          
          }else{
                  print_r($errors);
          }
       }
      if(empty($error)){
          echo "Success";
      }
      }
      ?&gt;
  </code></pre>