繁体   English   中英

将图像作为Blob类型插入数据库-Codeigniter

[英]Insert image in database as blob type - Codeigniter

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

我的模特有这个

 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

谢谢。

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

即使您要从函数访问值,也应将其写为$ this-> get_image() ,对于变量$ this-> get_image而不是$ 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);    
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM