file_get_contents()期望参数1为有效路径 [英] file_get_contents() expects parameter 1 to be a valid path

查看:67
本文介绍了file_get_contents()期望参数1为有效路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图像已成功上传到图像/新闻.我现在想将该图像保存在数据库中.但它总是给我上面的错误.我的模型查询是正确的,因为我使用它来插入其他数据并且它可以工作.

My image is uploading to images/news successfully. I want to now save that image in the database. but it keeps giving me the above error. My model query is correct because i use it to insert other data and it works.

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

How can i save the image into the database once the user clicks submit?

我的控制器:

 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 contain array values, you have to use upload_data

例如:

$ data = array('upload_data'=> $ this-> 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'] )
            );

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

you can directly use upload data function

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

这篇关于file_get_contents()期望参数1为有效路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆