Image 文件\u get\u contents()要求参数1为有效路径
我的图像已成功上载到图像/新闻。现在我想将该图像保存到数据库中。但它总是给我上述的错误。我的模型查询是正确的,因为我使用它来插入其他数据,它可以工作 用户单击提交后,如何将图像保存到数据库中 我的控制器:Image 文件\u get\u contents()要求参数1为有效路径,image,codeigniter,model-view-controller,controller,file-get-contents,Image,Codeigniter,Model View Controller,Controller,File Get Contents,我的图像已成功上载到图像/新闻。现在我想将该图像保存到数据库中。但它总是给我上述的错误。我的模型查询是正确的,因为我使用它来插入其他数据,它可以工作 用户单击提交后,如何将图像保存到数据库中 我的控制器: function news() { $config = array( 'upload_path' => "./images/news", 'allowed_types' => "gif|jpg|png|jpeg|JPG", 'overwrite' =>False, 'm
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');
}
$data包含数组值,必须使用upload_数据 例如: $data=array('upload_data'=>$this->upload->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())
);
仅供参考:您不能将文件保存到数据库中,这将使您以后的生活变得困难。尝试直接文件路径文件获取内容(/*上传文件paht*/);这就是我所做的:$data=array('image'=>file\u get\u contents(“./images/news”);您的文件名在哪里?将完整文件路径放置在此->$imagename=$this->upload->data()$数据=数组('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())
);