title: File upload Codeigniter and ajax
body: <p>I'm not sure what I'm doing wrong here. </p>
  
  <p>controller</p>
  
  <pre><code>function do_test()
  {
      $config['upload_path'] = './images';
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size'] = '10000';
      $config['max_width']  = '1024';
      $config['max_height']  = '768';
      $config['overwrite'] = TRUE;
      $confit['remove_spaces'] = TRUE;
  
      $this-&gt;load-&gt;library('upload', $config);
      $this-&gt;load-&gt;library('form_validation');
  
      $this-&gt;form_validation-&gt;set_rules('file', 'trim|required|xss_clean');
      $test = $this-&gt;input-&gt;post('file');
      var_dump($test); //var dump return : string(21) "C:\fakepath\truth.jpg"
  
      if ( ! $this-&gt;upload-&gt;do_upload($test))
      {
          echo "no";
      }
      else
      {
          $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
  
          echo "yes";
      }
  }
  </code></pre>
  
  <p>form</p>
  
  <pre><code>&lt;?php echo form_open_multipart('home/do_test', array( 'id' =&gt; 'skill-form-test' ) );?&gt;
  
      &lt;input type="file" name="userfile" id="file" size="20" /&gt;
  
      &lt;br /&gt;&lt;br /&gt;
  
      &lt;input type="submit" value="upload" /&gt;
  
      &lt;/form&gt;
  </code></pre>
  
  <p>jquery</p>
  
  <pre><code>$('#skill-form-test').submit(function(e) {
      e.preventDefault();
  
      $.post(base_url + "index.php/home/do_test", { file : $("#file").val()  }, function(data)
          {
              }, "json");
      alert ( $("#file").val() + "-" + base_url ); //This alerts: C:\fakepath\truth.jpg-http://siteurl.com/
  });
  </code></pre>