【问题标题】:How to fix no image?如何解决没有图像?
【发布时间】:2019-09-15 05:10:55
【问题描述】:

我尝试了以下代码并收到错误消息

错误号:1048 列brand_logo 不能为空 INSERT INTO tbl_brand (brand_name, brand_logo) VALUES ('Incoe', NULL)"

请帮我找出错误(对不起我的英语不好)

这是模特:

public function add_brand_model($brand_logo){
    $data['brand_name'] = $this->input->post('brand_name',true);
    $data['brand_logo'] = $brand_logo;
    $this->db->insert('tbl_brand',$data);
}

查看:

<div class="form-group">
   <label>Upload Brand Logo</label>
   <input type="file" name="brand_logo">
</div>

和控制器:

public function add_brand_form(){
    $data['main_content'] = $this->load->view('back/add_brand','',true);
    $this->load->view('back/adminpanel',$data);
}
public function save_brand(){
    $brand_logo= $this->upload_brand_logo();
    $this->form_validation->set_rules('brand_name','Brand Name','required|min_length[2]');
    if($this->form_validation->run()){
        $this->BrandModel->add_brand_model($brand_logo);
        $this->session->set_flashdata("flsh_msg","<font class='success'>Brand Added Successfully</font>");
           redirect('brand-list');
    }else{
        $this->add_brand_form();
    }
}
private function upload_brand_logo(){
    $config['upload_path']          = './uploads/';
    $config['allowed_types']        = 'png|gif|jpg|jpeg';
    $config['max_size']             = 1000;//kb
    $config['max_width']            = 1024;
    $config['max_height']           = 768;
    $this->load->library('upload', $config);
    if($this->upload->do_upload('brand_logo')){
        $data = $this->upload->data();
        $image_path = "uploads/$data[file_name]";
        return $image_path;
    }else{
          $error =  $this->upload->display_errors();
        $this->session->set_userdata('error_image',$error);
    }

}

【问题讨论】:

    标签: image codeigniter upload


    【解决方案1】:

    试试这个

    if($this->upload->do_upload('brand_logo')){
        $data = $this->upload->data();
        $image_path = "uploads/".$data[file_name]; //Change
        return $image_path;
    }else{
        $error =  $this->upload->display_errors();
        $this->session->set_userdata('error_image',$error);
        return false; //New addition
    }
    

    $image_path = '';
    if($this->upload->do_upload('brand_logo')){
        $data = $this->upload->data();
        $image_path = "uploads/".$data[file_name]; //Change
    }else{
        $error =  $this->upload->display_errors();
        $this->session->set_userdata('error_image',$error);
    }
    return $image_path; //return here only one time
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 2021-03-30
      相关资源
      最近更新 更多