i want to use do_upload function codeigniter and i have tried to solving this code with any tutorial. Please help me to solve this problem.
in controller:
function simpan_berita(){
$this->load->library('upload');
$config['upload_path'] = './assets/images/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['encrypt_name'] = TRUE;
$this->upload->initialize($config);
if(!empty($_FILES['filefoto']['name']))
{
if ($this->upload->do_upload('filefoto'))
{
$gbr = $this->upload->data();
//Compress Image
$config['image_library']='gd2';
$config['source_image']='./assets/images/'.$gbr['file_name'];
$config['create_thumb']= FALSE;
$config['maintain_ratio']= FALSE;
$config['quality']= '60%';
$config['width']= 840;
$config['height']= 450;
$config['new_image']= './assets/images/'.$gbr['file_name'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
...
echo $this->session->set_flashdata('msg','success');
redirect('user/berita');
}else{
echo $this->session->set_flashdata('msg','warning');
redirect('user/berita');
}
}else{
redirect('admin/berita');
}
}
and this is my views code:
<form action="<?php echo base_url().'user/berita/simpan_berita'?>" method="post" enctype="multipart/form-data">
...
<div class="form-group">
<label>Gambar</label>
<input type="file" name="filefoto" style="width: 100%;" required>
</div>
</div>
</div>
</form>
When i try to upload, other else condition will be run:
else{
echo $this->session->set_flashdata('msg','warning');
redirect('user/berita');
}
i need do_upload condition will be run. Please comment to help. Thankyou..