【发布时间】:2019-05-23 05:00:39
【问题描述】:
我正在尝试在 mysql 数据库中插入带有其他数据的图像,但它显示错误。 它显示未保存和重复视图文件数据的 $msg 可能是由于我设置的 $error。 PS:我在数据库中设置了“图像”数据类型 varchar。 这是我的视图文件:
<input type="file" class="form-control-file" name="image" id="exampleInputFile" >
这是我的控制器:
public function save()
{
$this->load->model('Partner_model');
$feature = $this->input->post('feature');
$config['upload_path'] = './uploads/files';
$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('image'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('partner_profile', $error);
}
else
{
$user_data= array(
'pname' => $this->input->post('pname'),
'type' => $this->input->post('type'),
'address' => $this->input->post('address'),
'about' => $this->input->post('about'),
'city' => $this->input->post('city'),
'code' => $this->input->post('code'),
'state'=>$this->input->post('state'),
// 'image'=>$this->upload->do_upload('image')
'feature'=>implode(",",$feature),
'image' => $this->upload->data()
);
}
if($this->Partner_model->save($user_data))
{
$msg = "save sucesss" ;
}
else
{
$msg = "not save";
}
$this->session->set_flashdata('msg', $msg);
$this->load->view('partner_profile');
}
}
&这是我的模特:
public function save($data)
{
return $this->db->insert('property', $data);
}
【问题讨论】:
-
"它显示错误。它显示未保存和重复视图文件数据的 $msg 可能是由于我设置的 $error。"不知道这是什么意思。你能分享你收到的确切错误输出吗?
-
您使用的是 form_open_multipart() 还是您的表单有“multipart”属性?这将需要处理上传。
-
$this->upload->data() 返回数组,您传递它只是为了保存在数据库中。 'image' => $this->upload->data() 行应该是 'image' => $this->upload->data()['file_name']
标签: mysql image codeigniter image-uploading