Image Upload in Codeigniter

write inside a function of controller

$data = $this->input->post();

$config['upload_path'] = './uploads/products/';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['encrypt_name'] = TRUE;

$this->load->library('upload',$config);
$this->upload->initialize($config);

if($this->upload->do_upload('img')){

$uploaddata = $this->upload->data();
$data['img'] = $uploaddata['file_name'];

$res = $this->my_model->insert_data('products',$data);
if($res){
echo 1;
}else{
echo 0;
}

}else{

echo 2;
}

Comments

Popular posts from this blog

Set Base URL in config file in Codeigniter

Form Validation Using Javascript

Image Display Inside Form