I'm now working in Codeigniter, have some issue in resizing the image while uploading. I have tried some code, but not working fine. Below I have added my file upload function:
public function add_to_event()
{
if (!empty($_FILES['event_image']['name'])) {
$config['upload_path'] = './images/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['image']['name']; //image upload-url to db and image to system directory
//Load upload library and initialize configuration
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('event_image')) {
$uploadData = $this->upload->data();
$image = $uploadData['file_name'];
} else {
$image = '';
}
}
else {
$image = '';
}
$image ="http://localhost/infi-admin/images/$image";
$event_title=$this->input->post('event_title');
$event_description=$this->input->post('event_description');
$this->load->model('User_model');
$data= array('event_title' =>$event_title ,
'event_description' =>$event_description,
'event_image'=>$image
);
$this->User_model->add_to_event_model($data);
redirect('Site/event_view');
}
this is my controller function to upload image along with other fields