File uploading error in Codeigniter File uploading error in Codeigniter codeigniter codeigniter

File uploading error in Codeigniter


Refer this code. this will surely work for you

public function uploadImage() {        $this->load->helper(array('form', 'url'));          $config['upload_path'] = 'assets/images/b2bcategory';        $config['allowed_types'] = 'gif|jpg|png';        $config['max_size'] = '1000';        $config['max_width'] = '2024';        $config['max_height'] = '1768';        $config['width'] = 75;        $config['height'] = 50;        if (isset($_FILES['catimage']['name'])) {            $filename = "-" . $_FILES['catimage']['name'];            $config['file_name'] = substr(md5(time()), 0, 28) . $filename;        }        $config['overwrite'] = TRUE;        $config['remove_spaces'] = TRUE;        $field_name = "catimage";        $this->load->library('upload', $config);        if ($this->input->post('selsub')) {            if (!$this->upload->do_upload('catimage')) {                //no file uploaded or failed upload                $error = array('error' => $this->upload->display_errors());            } else {                $dat = array('upload_data' => $this->upload->data());                $this->resize($dat['upload_data']['full_path'],           $dat['upload_data']['file_name']);            }            $ip = $_SERVER['REMOTE_ADDR'];            if (empty($dat['upload_data']['file_name'])) {                $catimage = '';            } else {                $catimage = $dat['upload_data']['file_name'];            }            $data = array(                            'ctg_image' => $catimage,                'ctg_dated' => time()            );            $this->b2bcategory_model->form_insert($data);        }    }


Change this:

<button>Submit</button>

to this :

<input type="submit" value="Submit" name="submit">

In Controller

class Pages extends CI_Controller {     public function data_submitted(){        $this->load->helper(array('form', 'url'));        $config['upload_path']   =   "./img/";        $config['allowed_types'] = 'gif|jpg|png'; # Changed         $this->load->library('upload',$config);        if(!$this->upload->do_upload())        {            $data = $this->upload->display_errors();        }        else{            $finfo = $this->upload->data();            $this->load->model('user_model');            $this->user_model->insert_item($finfo);        }        # Load the view on here    }}


You have to mention the field name in the do_upload method.

<form method="post" enctype="multipart/form-data">    <input type="file" name="field_name"/></form><?php $this->upload->do_upload('field_name'); ?>