title: How to insert multiple images name and move into the folder using jquery ajax in codeigniter?
body: <p>In my code, I have an input field <code>&lt;input type="file" id="product_image" name="product_image[]" multiple&gt;</code> where I want to insert muliple images name into my database as we as move images into folder. </p>
  
  <p>When I use <code>var_dump($_FILES)</code> it show me 
  <code>array(1) { ["product_image"]=&gt; array(5) { ["name"]=&gt; array(1) { [0]=&gt; string(9) "img3.jpeg" } ["type"]=&gt; array(1) { [0]=&gt; string(10) "image/jpeg" } ["tmp_name"]=&gt; array(1) { [0]=&gt; string(14) "/tmp/phpd6jSmA" } ["error"]=&gt; array(1) { [0]=&gt; int(0) } ["size"]=&gt; array(1) { [0]=&gt; int(40711) } } }</code></p>
  
  <p>View:   </p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function(){
          $("#submit").click(function(e){
              e.preventDefault();
              product_name = $("#product_name").val();
              quantity = $("#quantity").val();
              var formData = new FormData();
              $.each($("#product_image"), function (i, obj) {
                  $.each(obj.files, function (j, file) {                    
                      formData.append('product_image[' + i + ']', file);
                  });
              });
              formData.append('product_name', product_name);
              formData.append('quantity', quantity);
              $.ajax({
                  type:"POST",
                  data:formData,
                  processData: false,
                  contentType: false,
                  url:"&lt;?php echo base_url(); ?&gt;admin/products",
                  success:function(data){
                      $("#success_upload").html(data);
                  }
              });
          });
      });
  &lt;/script&gt;
  
  &lt;input type="text" class="form-control" id="product_name" name="product_name"&gt;
  &lt;input type="text" class="form-control" id="quantity" name="quantity"&gt;
  &lt;input type="file" id="product_image" name="product_image[]" multiple&gt;
  &lt;input type="submit" class="btn btn-primary" id="submit" name="submit"&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function products()
  {   
      $dataInfo = array();
      $files = $_FILES;
      $cpt = count($_FILES['product_image']['name']);
      for($i=0; $i&lt;$cpt; $i++)
      {           
          $_FILES['product_image']['name']= $files['product_image']['name'][$i];
          $_FILES['product_image']['type']= $files['product_image']['type'][$i];
          $_FILES['product_image']['tmp_name']= $files['product_image']['tmp_name'][$i];
          $_FILES['product_image']['error']= $files['product_image']['error'][$i];
          $_FILES['product_image']['size']= $files['product_image']['size'][$i];    
  
          $this-&gt;upload-&gt;initialize($this-&gt;set_upload_options());
          $this-&gt;upload-&gt;do_upload('product_image');
          $dataInfo[] = $this-&gt;upload-&gt;data();
      }
  
      $data = array(
              'product_name' =&gt; $this-&gt;input-&gt;post('product_name'),
              'quantity' =&gt; $this-&gt;input-&gt;post('quantity'),
              'product_image' =&gt; implode(",",array_column($dataInfo, 'product_image')),
          );
      $sql = $this-&gt;db-&gt;insert('add_product',$data);
      if($sql == true)
      {
          echo '&lt;p style="color:green;"&gt;New Product Added&lt;/p&gt;';
      }
      else
      {
          echo '&lt;p style="color:red;"&gt;Unable to Proceed!&lt;/p&gt;';
      }
  }
  
  private function set_upload_options()
  {   
      $config = array();
      $config['upload_path'] = ''.base_url().'resource/product/';
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size']      = '1024';
      $config['overwrite']     = FALSE;
      return $config;
  }
  </code></pre>
  
  <p>Now, only <code>product_name and quantity</code> are store in database but I also want to store <code>product_image</code> into my database which is separated by comma (,) like <code>img1.png,img2.png</code>. Please help me.</p>
  
  <p>Thank You</p>