title: How to add file names from all uploaded images to database in Codeigniter?
body: <p>I made an upload script to upload multiple images. This is working great, but I want to add the filenames to the database.</p>
  
  <p>My problem is that only the last image uploaded, is added to the database.
  This is because I don't know how to pass an data array to the model from the controller.</p>
  
  <p>My code to upload looks like this (controller):</p>
  
  <pre><code>public function aanbiedingenadd() //functie om ze toe te voegen aan de database
  {       
      $files = $_FILES;
      echo '&lt;pre&gt;';
      print_r($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();
          $image_data = $this-&gt;upload-&gt;data();
      }
      print_r($image_data);
      print_r($this-&gt;upload-&gt;display_errors());
      $this-&gt;aanbieding_model-&gt;addaanbieding($image_data);
      redirect("members/aanbiedingen");
  }
  </code></pre>
  
  <p><code>print_r($files)</code> shows me all the uploaded files with their size, width, height, etc.</p>
  
  <p><code>print_r($image_data);</code> only shows the last image uploaded.</p>
  
  <p>My model looks like this:</p>
  
  <pre><code>        $insert_data = array(
              'fotonaam' =&gt; $image_data['file_name']
          );
          print_r($insert_data);
          die;
          $input = $this-&gt;input-&gt;post('userfile');
          if(isset($input)){
              $this-&gt;db-&gt;insert('fotoaanbiedingen', $insert_data);
          }else{
              return FALSE;
          }
  </code></pre>
  
  <p><code>print_r($insert_data);</code> shows me </p>
  
  <pre><code>Array
  (
      [fotonaam] =&gt; 'nameoflastuploadedimage'
  )
  </code></pre>
  
  <p>How can I add this in an Array and add them one by one?</p>