title: Can't upload multiple image using Ajax with codeigniter
body: <p>Wana to upload multiple image with the help of Ajax in codeigniter but  got some error while calling the function upload_business_photo_do() please help</p>
  
  <p>thanks in advance....</p>
  
  <p></p>
  
  <pre><code>&lt;input type="button" id="uploadBusinessImg" value="Upload"&gt;
  </code></pre>
  
  <p>Ajax Code:- here i call ajax via <code>id="uploadBusinessImg"</code></p>
  
  <pre><code>&lt;script&gt;
  
      $("#uploadBusinessImg").on("click",function(e)
      {
           var total_img=$("#txtBusinessImage").get(0).files.length;
           if(total_img&lt;=5)
           {
               var f_size=0;
               var f_size_1=0;
               var f_type_1="" ,validFileName="",InValidFileName="";
               var chkFileValid=true;
               for(var i=0; i&lt;=total_img-1; i++)
               {
                   var f_name=$("#txtBusinessImage").get(0).files.item(i).name;
                   var f_size=$("#txtBusinessImage").get(0).files.item(i).size;
                   var f_type=f_name.split('.').pop();
                   //alert(f_type);
                   var valid_extensions = /(\.jpg|\.jpeg|\.png)$/i;
                   if(valid_extensions.test(f_name))
                      { 
                          if(validFileName=="")
                              validFileName =f_name;
                          else
                              validFileName+=","+f_name;
                      }
                   else
                      {   InValidFileName=f_name;
                          chkFileValid=false;
                          break;
                      }   
  
                  var newFileSize=parseInt(f_size);
                  f_size_1=parseInt(f_size_1)+parseInt(newFileSize);
  
               }
               var totalFileSize=f_size_1;
               //alert(totalFileSize);
               if(totalFileSize&lt;=1572864 &amp;&amp; chkFileValid==true)
               {
                   //alert("allow");
                   alert(validFileName);
                   var businessIMAGE=validFileName;
                   $.ajax({
                          type:"POST",
                          url:"&lt;?php echo site_url('Main_ctrl/upload_business_photo_do'); ?&gt;",
                          mimeType:"multipart/form-data",
                          uploadMultiple: true,
                          data:{reciveBusinessImg:businessIMAGE},
                          success: function(reviceUploadImgMsg)
                          {
                              alert(reviceUploadImgMsg);
                          }
                   });
  
               }
               else
               {   
                  if(chkFileValid==false)
                      alert("InValidFileName"+InValidFileName);
                  else
                      alert("Image size should be less then 1.5 MB");
               }
           }
           else
           {
              alert("Not Allow");
           }
  
  
      });
  
      &lt;/script&gt;
  </code></pre>
  
  <p>This is Controller Code:-</p>
  
  <pre><code>function upload_business_photo_do()
      {
          $reciveBusinessImgName=$this-&gt;input-&gt;post('reciveBusinessImg');
          $newArray=explode(",",$reciveBusinessImgName);
          /*code for image*/
                  $config['upload_path']='./company_image/';
                  $config['allowed_types']= 'jpg|png|jpeg';
                  $config['max_width'] = '6000';
                  $config['max_height'] = '4500';
  
                  $this-&gt;load-&gt;library('upload',$config);
  
  
                  for($i=0; $i&lt;count($newArray); $i++)
                  {
                      $_FILES['userfile']['name']= $_FILES['txtBusinessImage']['name'][$i];
  
                      $_FILES['userfile']['type']= $_FILES['txtBusinessImage']['type'][$i];
                      $_FILES['userfile']['tmp_name']= $_FILES['txtBusinessImage']['tmp_name'][$i];
                      $_FILES['userfile']['error']= $_FILES['txtBusinessImage']['error'][$i];
                      $_FILES['userfile']['size']= $_FILES['txtBusinessImage']['size'][$i];
  
  
                          if(! $this-&gt;upload-&gt;do_upload())
                          {
                              /*----set flash message*/
                              echo "error";
  
  
                          }
                          else
                          {
                              $upload_data = $this-&gt;upload-&gt;data();
                               echo "done";
                          }
  
                  }
      }
  </code></pre>