Organizational Research By

Surprising Reserch Topic

ajax file upload using codeigniter


ajax file upload using codeigniter  using -'php,jquery,ajax,codeigniter,file-upload'

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:

(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);


I call it like this:

$(document).ready(function() {    
    $('#myForm').ajaxSubmit();
});


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.

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.
    
asked Sep 15, 2015 by Phi2283
0 votes
14 views



Related Hot Questions



Government Jobs Opening

" rel="nofollow" target="_blank">https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> " rel="nofollow" target="_blank">http://malsup.github.com/jquery.form.js">
0%

In CodeIgniter Controller :

Hope this helps you. Thanks!!

answered Sep 15, 2015 by NoeRosenber

...