CodeIgniter Forums
File upload class + ajax jquery - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: File upload class + ajax jquery (/showthread.php?tid=25187)



File upload class + ajax jquery - El Forum - 12-03-2009

[eluser]Unknown[/eluser]
Hi all

I use the file upload class and it's work perfecly but I would like to use ajax jquery code to call the controller because I want to make small progress bar to let user know the file is currently in progress....

The javascript code
Code:
[removed]

var userfile = document.getElementById("userfile").value;
// the userfile is the id of the input

$.ajax({
   type: "POST",
   url: "index.php/inscription/postfile",
   data: ({
            userfile: userfile,
         }),
   success: function(msg){
    // alert( "File saved: " + msg );
   }
});

[removed]

The php controller
Code:
function postfile()
    {
        

        $is_logged_in = $this->session->userdata('is_logged_in');
        if($is_logged_in){
        
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
             echo "Error :".$error;
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            echo "Succes";  

        }
            
        }else{
            echo "Not allowed to send file";
        }
        
        
    }

it's not working..... if I use the file upload class only work perfecly ....it is possible to archive this?

thanks for your help.


File upload class + ajax jquery - El Forum - 12-03-2009

[eluser]umefarooq[/eluser]
hi check the link will help you for your problem jquery uploadify working with CI

http://www.reloadedpc.com/code-igniter/jquery-uploadify-2-codeigniter/

also check this forum post

http://ellislab.com/forums/viewthread/109751/