I am trying to upload an image in codeigniter.
here is my view file code.
<form action="<?php echo site_url('pages/data_submitted') ?>" method="get" enctype="multipart/form-data">
Image: <input type="file" name="image"/>
<button>Submit</button>
</form>
and this is my controller code.
class Pages extends CI_Controller
{
public function data_submitted(){
$config['upload_path'] = "img/";
$this->load->library('upload',$config);
$this->upload->do_upload();
$finfo=$this->upload->data();
$data = $this->upload->display_errors();
$this->load->model('user_model');
$this->user_model->insert_item($data);
}
}
and here is my model code
<?php
class User_model extends CI_Model {
function __construct(){
/* Call the Model constructor */
parent::__construct();
}
public function insert_item($item){
print_r($item);
}
}
?>
What is wrong with this code... Here I passed $data just to check whether any error occur or not. And it is showing "You did not select a file to upload.' even I select a file. please help me.