title: Codeigniter form submit with file upload
body: <p>im trying to write a code where i can submit a form enter the contents in a database, at the same time perform a file upload and have it stored in a folder inside my server</p>
  
  <p>the folder location is called uploads which is located at the root of my site</p>
  
  <p>here is my code</p>
  
  <p>controller (site.php)</p>
  
  <pre><code> &lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
   class Site extends CI_controller {
  
  public function __construct()
  {
      parent::__construct();
      // Your own constructor code
      $this-&gt;load-&gt;model("site_model");
      $this-&gt;load-&gt;helper(array('form', 'url'));
  } 
  
  public function cmain($type,$page)
  {
      $data = $this-&gt;_initialize_data(); //this is just a bunch of variables that im calling in another function
      $data['type'] = $type;
      $data['page'] = $page;
      $this-&gt;load-&gt;vars($data);
      $this-&gt;load-&gt;view('site/cmain');
  }
  
  
  public function m1()
          {               
  
          $this-&gt;load-&gt;library('upload', $config);
  
              if(isset($_POST['m1']))
              {
                  $suffix = $this-&gt;input-&gt;post("suffix");
                  $fn = $this-&gt;input-&gt;post("fn");
                  $mn = $this-&gt;input-&gt;post("mn");
                  $ln = $this-&gt;input-&gt;post("ln");
  
  
                  $newdata = array('suffix'=&gt;$suffix,
                                  'fn'=&gt;$fn,
                                  'mn'=&gt;$mn,
                                  'ln'=&gt;$ln,
  
                                   );
                  //this code is for the file upload
                             $config['upload_path'] = 'uploads';
                             $config['allowed_types'] = '*';
  
                             $this-&gt;load-&gt;library('upload', $config);
  
                             $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
                   //end of file upload codes                 
  
                  $this-&gt;db-&gt;insert('myself', $newdata); 
  
                  redirect(base_url() . "site/complaint");    
  
              }
  
          }
  </code></pre>
  
  <p>view (cmain.php)</p>
  
  <pre><code>&lt;form action="&lt;?php echo base_url();?&gt;site/m1" name="details" id="details" method="post" enctype="multipart/form-data"&gt;
          &lt;table class='table' width="100%"&gt;
              &lt;tr&gt;
              &lt;td colspan='2'&gt;
                  &lt;b&gt;&lt;font color="#3B608C"&gt;Personal Information&lt;/font&gt;&lt;/b&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Suffix  (e.g. Jr., III)
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="text" name="suffix" id="suffix" value=""&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  First Name*
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="text" name="fn" id="fn" value=""&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Middle Name*
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="text" name="mn" id="mn" value=""&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Last Name*
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="text" name="ln" id="ln" value=""&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  &lt;/table&gt;
  
              &lt;table&gt;
          &lt;tr&gt;
          &lt;td width="50%"&gt;
          Please attach documents pertinent to these complaints. &lt;br&gt;
          (Attach a zip file if more than one document)&lt;br&gt;
          &lt;/td&gt;
          &lt;td align="center"&gt;
          &lt;input name = "userfile" type="file" class="input-xlarge" id = "userfile" /&gt;
          &lt;/td&gt;&lt;/tr&gt;
          &lt;/table&gt;
          &lt;input type="submit" value="Submit Form" class="pull-right" id="submit" name="m1"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>the form posts properly in the database like the suffix,fn,ln and mn
  however the file upload isnt working</p>
  
  <p>i tried my best to follow what the codeigniter docs samples and only got the lines i think i needed</p>
  
  <p>am i doing something wrong?</p>
  
  <p>thanks</p>