file_get_contents() 期望参数 1 是有效路径

file_get_contents() expects parameter 1 to be a valid path

我的图片正在成功上传到 images/news。我现在想将该图像保存在数据库中。但它一直给我上述错误。我的模型查询是正确的,因为我用它来插入其他数据并且它有效。

如何在用户点击提交后将图像保存到数据库中?

我的控制器:

 function news()
{

 $config = array(
'upload_path' => "./images/news",
'allowed_types' => "gif|jpg|png|jpeg|JPG",
'overwrite' =>False,
'max_size' => "2048000", 
'max_height' => "768",
'max_width' => "1024"
);
    $this->load->library('upload', $config);

    $this->load->helper(array('form', 'url'));

    if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
 $this->load->view('manage_news',$data);
}
else
 {
 $message2 = "Please choose another file type. gif,jpg,png,jpeg,pdf ";
         echo "<script type='text/javascript'>alert('$message2');   </script>";                 
          redirect('resetPasswordController/add_news', 'refresh');
       }

        $this->db->trans_start();

        $data = array('upload_data' => $this->upload->data());

        $data = array(          
            'image' => file_get_contents( $data )
            );

         $this->load->model('users_model'); 
        $this->users_model->insert($data);    

        $this->db->trans_complete();
        $this->db->trans_complete();

        redirect('resetPasswordController/manage_news', 'refresh');
  }

我的看法:

 <?php echo form_open_multipart('resetPasswordController/news');?>
 <label>Image</label>
<input name = "userfile" type="file" />

我的模特:

 function insert($data){
        $this->db->insert('news',$data);
        return $this->db->insert_id();
}

$data 包含数组值,你必须使用 upload_data

例如:

$data = array('upload_data' => $this->upload->data());

$data = array(          
    'image' => file_get_contents( $data )
    );

将此更改为

$data = array('upload_data' => $this->upload->data());

        $data = array(          
            'image' => file_get_contents( $data['upload_data'] )
            );

可以直接使用上传数据功能

            $data = array(          
                'image' => file_get_contents(  $this->upload->data())
                );