title: Multiple image upload with Codeigniter saving only one file path to MySQL Database
body: <p>Now I'm building an application. I have set up a form that will upload multiple image to database. This is my simple code </p>
  
  <p><strong>View</strong> </p>
  
  <pre><code>&lt;?php echo form_open_multipart('admin/product/post'); ?&gt;
  &lt;table class="table table-stripped"&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Code&lt;/td&gt;
              &lt;td&gt;
                  &lt;?php echo form_input(array('class'=&gt;'form-control','name'=&gt;'kodeproduk')); ?&gt;                                  
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Display&lt;/td&gt;
              &lt;td&gt;
                  &lt;input class="form-control" type="file" name="userfile[]" id="multiple" multiple="" /&gt;    
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Description&lt;/td&gt;
              &lt;td&gt;
                  &lt;div class="textarea textarea-editor"&gt;
                      &lt;textarea name="ket" cols="50" rows="5" class="form-control"&gt;&lt;/textarea&gt;
                  &lt;/div&gt;                                  
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="2"&gt;
                  &lt;button type="submit" class="btn btn-primary btn-outline btn-block pull-right"&gt;&lt;span&gt;Save&lt;/span&gt;&lt;/button&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;?php echo form_close(); ?&gt;
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function post(){        
      if($this-&gt;_validation()===FALSE){ 
          $this-&gt;session-&gt;set_flashdata('error', 'Ooops, there was an error');
          redirect(base_url("admin/product"));
      }else{
          $files = $_FILES;
          $cpt = count($_FILES['userfile']['name']);
              for($i=0; $i&lt;$cpt; $i++){
              $_FILES['userfile']['name']= $files['userfile']['name'][$i];
              $_FILES['userfile']['type']= $files['userfile']['type'][$i];
              $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
              $_FILES['userfile']['error']= $files['userfile']['error'][$i];
              $_FILES['userfile']['size']= $files['userfile']['size'][$i];
              $this-&gt;upload-&gt;initialize($this-&gt;set_upload_options());
              $this-&gt;upload-&gt;do_upload();
              $fileName = $_FILES['userfile']['name'];
              $images[] = $fileName;
          }
          $fileName = implode(',',$images);
  
          $data = array(  'kodeProduk'                =&gt; $this-&gt;input-&gt;post('kodeproduk'),
                          'ket'                       =&gt; $this-&gt;input-&gt;post('ket'),
  
                          'GambarBesar'               =&gt; $fileName
          );
  
          unset($data['submit']);                             
          $this-&gt;table-&gt;add_record($data);
          $this-&gt;session-&gt;set_flashdata('success', 'Product has been saved.');
          redirect(base_url("admin/product"));
      }   
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public function add_record($data){
      $this-&gt;db-&gt;insert('produk', $data);
      return;
  }
  </code></pre>
  
  <p>And I have a problem when I'm post it, all of the image files upload to the directory on the server, but only ONE of the images actually stores into the MySQL table as a row. So how to fixed my code ? Thanks advance </p>