title: Ajax File Upload using Codeigniter
body: <p>I'm trying to upload an image using codeigniter and ajax. I already have the ajax method to insert the field values to the DB, what's the easiest and simplest way to upload my file.
  Here's the JQuery custom function:</p>
  
  <pre><code>(function($){
      jQuery.fn.ajaxSubmit =
          function() {
              $(this).submit(function(event) {
                  event.preventDefault();
                  var url = $(this).attr('action');                       
                  var data = $(this).serialize();
  
                  $.ajax({
                      url: url,
                      type: "POST",
                      data: data,
                      dataType: "html",
                      success: function(msg) {
                                 $('#main').html(msg);
                               }
                         });
  
                   return this;
               });
           };
  })(jQuery);
  </code></pre>
  
  <p>I call it like this:</p>
  
  <pre><code>$(document).ready(function() {    
      $('#myForm').ajaxSubmit();
  });
  </code></pre>
  
  <p>The function works fine, the data gets inserted in the database and I even have some directories that get created in the model before uploading the image, they are created but the image is not uploaded at all.</p>
  
  <p>I know I need to use a hidden Iframe to do the job, but I dont quite know how to integrate that in my code.</p>