将图像作为Blob类型插入数据库-Codeigniter [英] Insert image in database as blob type - Codeigniter

查看:76
本文介绍了将图像作为Blob类型插入数据库-Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用codeigniter将图像作为Blob类型存储在数据库中。我不想将图像上传到文件夹中。我只想将图像作为blob存储在db中。

I need to store the image as blob type in database using codeigniter. I don't want to upload the image in a folder. I just wanted to store the image in db as blob.

我的模型中有此

 public function insert_user()
 {    
    $get_image = $this->input->post(file_get_contents($_FILES['imgProfile']['tmp_name']));  //imgProfile is the name of the image tag  
    $insert_values = array(
            'first_name' => $this->input->post('FirstName'),
            'last_name' => $this->input->post('LastName'),
            'profile_image' => $this->$get_image 
            );  

    $insert_qry = $this->db->insert('user', $insert_values);    
    }

我的控制器包含

public function new_user()
{
        $this->user_model->insert_user(); //user_model is the model name
}

错误:

Fatal error: Cannot access empty property in C:\xampp\htdocs\CI\system\core\Model.php on line 52

谢谢。

推荐答案

在您的代码中,您有与变量有关的错字。看来您可能将变量称为函数

Within your code you have typo related to variable. It seems you might be calling your variable as function.

即使您要从函数访问值,也应将其写为 $ this-> get_image(),而对于变量 $ this-> get_image $ this-> $ get_image

Even though if you want to access the value from a function then it should be written as $this->get_image() and for variables $this->get_image not as $this->$get_image

public function insert_user()
 {    
    $get_image = $this->input->post(file_get_contents($_FILES['imgProfile']['tmp_name']));  //imgProfile is the name of the image tag  
    $insert_values = array(
            'first_name' => $this->input->post('FirstName'),
            'last_name' => $this->input->post('LastName'),
            'profile_image' => $get_image //its a variable
            );  

    $insert_qry = $this->db->insert('user', $insert_values);    
    }

这篇关于将图像作为Blob类型插入数据库-Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆