title: How to upload image path and name to database - Codeigniter
body: <p>I know that this question has been asked several times, but all the other question I found are different from what I want.</p>
  
  <p>I want to upload the filename and filepath to a table called 'factoryimages'.</p>
  
  <p>What's the best way of doing this?</p>
  
  <p>My controller function:</p>
  
  <pre><code>function do_upload()
  {
      $config['upload_path'] = './assets/uploads/';
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size'] = '1000';
      $config['max_width']  = '';
      $config['max_height']  = '';
      $config['overwrite'] = TRUE;
      $config['remove_spaces'] = TRUE;
  
      $this-&gt;load-&gt;library('upload', $config);
  
      if ( ! $this-&gt;upload-&gt;do_upload())
      {
          $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
  
          $this-&gt;load-&gt;view('members/header');
          $this-&gt;load-&gt;view('members/upload_form', $error);
          $this-&gt;load-&gt;view('members/footer');
      }
      else
      {
          $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
          $this-&gt;load-&gt;view('members/header');
          $this-&gt;load-&gt;view('members/upload_success', $data);
          $this-&gt;load-&gt;view('members/footer');
      }
  }
  </code></pre>
  
  <p>I tried this in my model, but it didn't work:</p>
  
  <pre><code>function insert_images()
  {
      $insert_data = array(
      'filename' =&gt; $image_data['file_name'],
      'fullpath' =&gt; $image_data['full_path']
      );
  
      $this-&gt;db-&gt;insert('bedrijfimages', $insert_data);
  }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;?php echo $error;?&gt;
  &lt;br/&gt;
  &lt;?php echo form_open_multipart('upload/do_upload');?&gt;
  
  &lt;input type="file" name="userfile" size="20" multiple="true" /&gt;
  
  &lt;br /&gt;&lt;br /&gt;
  
  &lt;input type="submit" value="upload" /&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <h1>Edit:</h1>
  
  <p>I get an server error but i can't see what it is.</p>
  
  <p>My controller function:</p>
  
  <pre><code>function do_upload()
  {
      $config['upload_path'] = './assets/uploads/';
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size'] = '1000';
      $config['max_width']  = '';
      $config['max_height']  = '';
      $config['overwrite'] = TRUE;
      $config['remove_spaces'] = TRUE;
  
      $this-&gt;load-&gt;library('upload', $config);
  
      if ( ! $this-&gt;upload-&gt;do_upload())
      {
          $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
          $this-&gt;upload_model-&gt;insert_images($this-&gt;upload-&gt;data());
          $this-&gt;load-&gt;view('members/header');
          $this-&gt;load-&gt;view('members/upload_form', $error);
          $this-&gt;load-&gt;view('members/footer');
      }
      else
      {
          $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
          $this-&gt;load-&gt;view('members/header');
          $this-&gt;load-&gt;view('members/upload_success', $data);
          $this-&gt;load-&gt;view('members/footer');
      }
  }
  </code></pre>
  
  <p>My model function:</p>
  
  <pre><code>function insert_images($data = array())
  {
      $data = array(
      'filename' =&gt; $image_data['file_name'],
      'fullpath' =&gt; $image_data['full_path']
      );
  
      $this-&gt;db-&gt;insert('bedrijfimages', $data);
  }
  </code></pre>
  
  <p>What could be the problem?</p>