FETCHING ID of the user who posted the file and post it in the database

I am trying to upload profile pictures for my users using code igniter.the syntax for thposting the image in the file systeme is quite ok all i need to know =now is how can i add a userid to each specific image.i tried using the code below but it returns 0 as the user ID

function seekerImageStore()  
    {  
         if(isset($_FILES["image_file"]["name"]))  
         {   $user = $this->session->userdata('myuserid_vipajijobs');
              $config['upload_path'] = './uploads/seekerimages';  
              $config['allowed_types'] = 'jpg|jpeg|png|gif';  
              $this->load->library('upload', $config);  
              if(!$this->upload->do_upload('image_file'))  
              {  
                  $error =  $this->upload->display_errors(); 
                  echo json_encode(array('msg' => $error, 'success' => false));
              }  
              else 
              {   $user = $this->session->userdata('myuserid_vipajijobs');
                  $data = $this->upload->data(); 
                   $insert['name'] = $data['file_name'];
                   $this->db->insert('images',$insert);
                   $pic=$this->input->post('image_file');
 $this->db->insert('images',['user'=>$user,'name'=>$pic]);

                   $getId = $this->db->insert_id();   






                   $arr = array('msg' => 'Image has not uploaded successfully', 'success' => false);

                   if($getId){
                       $arr = array('msg' => 'Image has been uploaded successfully', 'success' => true);

              }  

         }  
    }

Leave a Reply

Your email address will not be published. Required fields are marked *