function do_upload(){
$config['upload_path'] = './public/assets/img_content/'; //path folder
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['encrypt_name'] = FALSE;
$this->upload->initialize($config);
if(!empty($_FILES['filefoto']['name'])){
if ($this->upload->do_upload('filefoto')){
$gbr = $this->upload->data();
//Compress Image
$this->_create_thumbs($gbr['file_name']);
$this->session->set_flashdata('msg','<div class="alert alert-info">Image Upload Successful.</div>');
redirect('upload');
}else{
echo $this->upload->display_errors();
}
}else{
echo "image is empty or type of image not allowed";
}
}
function _create_thumbs($file_name){
// Image resizing config
$config = array(
// Large Image
array(
'image_library' => 'GD2',
'source_image' => './public/assets/img_content/'.$file_name,
'maintain_ratio'=> FALSE,
'width' => 700,
'height' => 467,
'new_image' => './public/assets/img_content/large/'.$file_name
),
// Medium Image
array(
'image_library' => 'GD2',
'source_image' => './public/assets/img_content/'.$file_name,
'maintain_ratio'=> FALSE,
'width' => 600,
'height' => 400,
'new_image' => './public/assets/img_content/medium/'.$file_name
),
// Small Image
array(
'image_library' => 'GD2',
'source_image' => './public/assets/img_content/'.$file_name,
'maintain_ratio'=> FALSE,
'width' => 100,
'height' => 67,
'new_image' => './public/assets/img_content/small/'.$file_name
));
$this->load->library('image_lib', $config[0]);
foreach ($config as $item){
$this->image_lib->initialize($item);
if(!$this->image_lib->resize()){
return false;
}
$this->image_lib->clear();
}
}