Welcome Guest, Not a member yet? Register   Sign In
Image uploading with ajax!
#1

I am not sure what i am doing wrong with my code from controller! here is the code to upload image via ajax submission:
PHP Code:
public function post()
    {
        
$formrules = array(
            array(
                
'field' => 'title',
                
'label' => 'News Link',
                
'rules' => 'required|max_length[200]'
            
),
            array(
                
'field' => 'news',
                
'label' => 'News Snippet',
                
'rules' => 'required|max_length[2500]'
            
)
        );

        
$this->form_validation->set_rules($formrules);

        if (
$this->form_validation->run() == TRUE)
        {
            
# Started working with file upload.
            
$validFiles = array(
                
'upload_path'   => 'tmp_data/',
                
'allowed_types' => 'jpg|png|gif',
                
'max_size'      => 250
            
);
            
$this->load->library('upload'$validFiles);
            if (
$this->upload->do_upload('newsphoto'))
            {
                echo 
"Image Uploaded Successfully!";
                
# Add data to db.
                
$this->load->model('links');
                
$data = array(
                    
'title' => $this->input->post('title'),
                    
'news'  => $this->input->post('news')
                );
                
$this->links->add($data);
            }
            else
            {
                echo 
$this->upload->display_errors();
            }
            
# End all the process of file upload.
        
}
        else
        {
            echo 
validation_errors();
        }
    } 
it is a method of a controller, but every time i started to upload something it seems to be an error, a msg shows like this:
Quote:You did not select a file to upload.
any idea on what i am missing?
Thanks CI Community Smile
Reply


Messages In This Thread
Image uploading with ajax! - by rakibtg - 03-23-2015, 01:47 AM
RE: Image uploading with ajax! - by techbat - 03-23-2015, 02:00 AM
RE: Image uploading with ajax! - by rakibtg - 03-23-2015, 02:14 AM
RE: Image uploading with ajax! - by techbat - 03-23-2015, 02:24 AM
RE: Image uploading with ajax! - by rakibtg - 03-23-2015, 04:40 AM
RE: Image uploading with ajax! - by techbat - 03-23-2015, 06:00 AM
RE: Image uploading with ajax! - by rakibtg - 03-24-2015, 07:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB