php ci上传图片,php-将图像上传到Codeigniter中的MySQL数据库Bl...

模型中的$this-> input-> post(‘photo’)将无法检索图像信息.因为图像存储在$_FILES中而不是$_POST中.因此,您需要在codeignitor中使用upload library,如下所示.

In Controller:

public function update_profile() {

$id = $this->session->userdata('id');

$this->load->model('edit_profile_model');

$config['upload_path'] = './uploads/';

$config['allowed_types'] = 'gif|jpg|png';

$config['max_size'] = '100';

$config['max_width'] = '1024';

$config['max_height'] = '768';

$this->load->library('upload', $config);

$this->upload->do_upload();//upload the file to the above mentioned path

$this->edit_profile_model->update_db_user_info($id, $this->upload->data());// pass the uploaded information to the model

}

In Model:

public function update_db_user_info($id, $imgdata) {

$imgdata = file_get_contents($imgdata['full_path']);//get the content of the image using its path

$data = array(

'fullname' => $this->input->post('fullname'),

'address' => $this->input->post('address'),

'state' => $this->input->post('state'),

'city' => $this->input->post('city'),

'pincode' => $this->input->post('pincode'),

'image' => $imgdata,

);

$this->db->where('id', $id);

$this->db->update('userdetails', $data);

}

要检索图像,请在下面的模型中编写一个函数.

public function get_image($id){

$this->db->where('id', $id);

$result = $this->db->get('userdetails');

header("Content-type: image/jpeg");

echo $result['image'];

}

而且,存储图像并从数据库检索也不是一个好习惯.与其尝试将图像存储在文件夹中,然后将路径存储在数据库中,如下所示.

In Model:

public function update_db_user_info($id, $imgdata) {

$imgdata = $imgdata['full_path'];// get the path of the image

$data = array(

'fullname' => $this->input->post('fullname'),

'address' => $this->input->post('address'),

'state' => $this->input->post('state'),

'city' => $this->input->post('city'),

'pincode' => $this->input->post('pincode'),

'image' => $imgdata,// change the type of image from blob to varchar or text

);

$this->db->where('id', $id);

$this->db->update('userdetails', $data);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值