image - file_get_contents() expects parameter 1 to be a valid path -


my image uploading images/news successfully. want save image in database. keeps giving me above error. model query correct because use insert other data , works.

how can save image database once user clicks submit?

my controller:

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

my view:

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

my model:

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

$data contain array values, have use upload_data

for ex :

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

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

change

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

or

you can directly use upload data function

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

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -