简体   繁体   中英

Insert image in database as blob type - Codeigniter

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.

I have this in my model

 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);    
    }

My controller contains

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

Error:

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

Thanks.

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

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);    
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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