2015-04-23 79 views
-1

我需要使用codeigniter將圖像作爲Blob類型存儲在數據庫中。我不想將圖片上傳到文件夾中。我只是想將圖像作爲blob存儲在數據庫中。以blob類型在數據庫中插入圖像 - Codeigniter

我有這個在我的模型

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 

感謝。

+0

什麼是Model.php中的L52? – Florian

+0

參考$ this - > $ getimage是錯誤的,它應該是$ this-> getimage或者簡單的$ getimage(在本地函數中使用) –

回答

2

在你的代碼中,你有與變量相關的錯字。看起來你可能會打電話給你的variable作爲function

即使如果你想從一個函數,那麼它應該被寫成$這個 - > get_image()和變量$這個 - 訪問值> get_image沒有$本 - > $ 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);  
    } 
相關問題