title: How to insert file_path into database using codeigniter
body: <p>I am  having a problem with inserting file_path to database usingt Codeigniter, I have a form field where user can upload any jpg|png|gif file ,the uploaded file is successfully sent to a uploads directory and a success message is displayed. But how will I get the file_path of that particular file uploaded and insert it into database.</p>
  
  <p>the code below works fine until I call the model:</p>
  
  <pre><code>`$this-&gt;upload_model-&gt;upload_path();`
  </code></pre>
  
  <p>so definately there is a problem with my model ,cant figure out.</p>
  
  <p>This is my Controller:</p>
  
  <pre><code>class Upload extends CI_Controller {
  
          public function __construct()
          {
                  parent::__construct();
                  $this-&gt;load-&gt;helper(array('form', 'url'));
                  $this-&gt;load-&gt;model('upload_model');
          }
  
          public function index()
          {
                  $this-&gt;load-&gt;view('upload_form', array('error' =&gt; ' ' ));
          }
  
          public function do_upload()
          {
                  $config['upload_path']          = './uploads/';
                  $config['allowed_types']        = 'gif|jpg|png';
                  $config['max_size']             = 100;
                  $config['max_width']            = 1024;
                  $config['max_height']           = 768;
  
                  $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('upload_form', $error);
                  }
                  else
                  {
                          $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
  
                          // when the code below is uncommented it shows error,otherwise runs
                          // $this-&gt;upload_model-&gt;upload_path();
  
                          $this-&gt;load-&gt;view('upload_success', $data);
  
                  }
          }
  }
  </code></pre>
  
  <p>This is my model(which shows error):</p>
  
  <pre><code>class Upload_model extends CI_Model {
  
  // this function will be called instantenneously
  
      public function __construct()
      {
          parent::__construct();
  
          $this-&gt;load-&gt;database();
      }
      public function upload_path(){
  
  // ::::::::UNDER CONSTRUCTION::::::::::
  
          $data = array(
              'path' =&gt;$upload_data['full_path'],
  
              );
  
          return $this-&gt;db-&gt;insert('upload', $data);
  
  
      }
  
  }
  </code></pre>
  
  <p>the View:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Upload Form&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;?php echo $error;?&gt;
  
      &lt;form method="POST" action="/sandeep/ci/index.php/upload/do_upload" enctype="multipart/form-data" /&gt;
  
      &lt;input type="file" name="userfile" size="20" /&gt;
  
      &lt;br /&gt;&lt;br /&gt;
  
      &lt;input type="submit" value="upload" /&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>