if a image is choosed then i want to upload that image and store filename to db else i want to store in db filename as "default_brand.png" and no file is going to upload . in following do_upload function if errors occured then i want to display that error on same view, if no error and image uploaded successfully i want to display success message. what changes i have to do for following code.
function index()
{
//some statements.
if (empty($_FILES['brand_image']['name'])) {
$filename = 'default_brand.png';
}
else {
$filename = $this->do_upload();
}
echo $filename;
}
function do_upload()
{
$config['upload_path'] = './assets/public_image/brand';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('brand_image'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->model('get_data_model');
$resultset = $this->get_data_model->get_only_child_categories();
$data['resultset'] = $resultset;
$this->layouts->view('brand_view', array('left_sidebar' => 'sidebar/left_sidebar','right_sidebar' => 'sidebar/right_sidebar'),$data,true);
return "default_brand.png";
}
else
{
$data = array('upload_data' => $this->upload->data());
$filename = $data['file_name'];
return $filename;
}
}