title: Codeigniter Upload featured image and multiple images at the same time
body: <p>I have modified the code to use a foreach loop, now I can access the files names, and the <code>print_r</code> is printing the files names in an array like this:</p>
  
  <pre><code>Array ( [0] =&gt; Uconn.png [1] =&gt; UW_Medicine.png [2] =&gt; Yale.png ) Axis.png
  </code></pre>
  
  <p>but I am still getting the following error: </p>
  
  <pre><code>A PHP Error was encountered
  
  Severity: Notice
  
  Message: Array to string conversion
  </code></pre>
  
  <p>and a databse error:</p>
  
  <pre><code>Error Number: 1054
  
  Unknown column 'Array' in 'field list'
  
  INSERT INTO `yacht_slider` (`yacht_slide_id`, `slide`) VALUES (87, Array)
  </code></pre>
  
  <p>I just don't know how should I pass the looped files inside the model to upload.</p>
  
  <p>I am trying to upload a featured image in one input, and multiple images in another input at the same time, I tried many ways and methods to do this, but I always end with an error, mostly Array to string conversion error.</p>
  
  <p>the featured image is stored in one database table and the multiple images are stored in another table.</p>
  
  <p>My current code:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
            &lt;label for="" class="control-label"&gt;Image&lt;/label&gt;
            &lt;input type="file" class="form-control" name="featured"&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="" class="control-label"&gt;Slider&lt;/label&gt;
            &lt;input type="file" class="form-control" name="userfile[]" multiple&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public function create_yacht($yacht_img, $slider){
    $slug = url_title($this-&gt;input-&gt;post('title'));
    $data = array(
      'title' =&gt; $this-&gt;input-&gt;post('title'),
      'slug' =&gt; $slug,
      'img' =&gt; $yacht_img,
      'city' =&gt; $this-&gt;input-&gt;post('city'),
      'category' =&gt; $this-&gt;input-&gt;post('category'),
      'price' =&gt; $this-&gt;input-&gt;post('price'),
      'description' =&gt; $this-&gt;input-&gt;post('description')
    );
    $this-&gt;db-&gt;insert('yachts', $data);
    $insert_id = $this-&gt;db-&gt;insert_id();
    $data_4 = array(
      'yacht_slide_id' =&gt; $insert_id,
      'slide' =&gt; $slider
    );
    $this-&gt;db-&gt;insert('yacht_slider', $data_4);
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function create_yacht(){
    $data['title'] = 'Create';
    $data['categories'] = $this-&gt;category_model-&gt;get_categories();
    $this-&gt;form_validation-&gt;set_rules('title', 'Title', 'required');
    $this-&gt;form_validation-&gt;set_rules('city', 'City', 'required');
    if($this-&gt;form_validation-&gt;run() === FALSE){
      $this-&gt;load-&gt;view('templates/admin_header');
      $this-&gt;load-&gt;view('admin/create_yacht', $data);
      $this-&gt;load-&gt;view('templates/admin_footer');
    }else{
      $config['upload_path'] = './assets/images';
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size'] = '2048';
      $this-&gt;load-&gt;library('upload', $config);
      $featured = 'featured';
      if (!$this-&gt;upload-&gt;do_upload($featured)) {
        $errors = array('errors' =&gt; $this-&gt;upload-&gt;display_errors());
        $yacht_img = 'https://via.placeholder.com/1920x1080';
      }else{
        $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
        $yacht_img = $_FILES['featured']['name'];
      }
      foreach ($_FILES['userfile']['name'] as $name) {
        $this-&gt;upload-&gt;initialize($config);
        $this-&gt;upload-&gt;do_upload($name);
        $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
        $slider = $_FILES['userfile']['name'];
      }
      print_r($slider);
      print_r($yacht_img);
      $this-&gt;yacht_model-&gt;create_yacht($yacht_img, $slider);
      // redirect('admin');
    }
  }
  </code></pre>