ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Display profile image from database : codeigniter

April 14, 2013 8:25am

Subscribe [1]
  • #1 / Apr 14, 2013 8:25am

    vash1981

    2 posts

    Hi guys I am trying to display image stored in the database. I saved the name of the file in a field called ‘profile_picture’ in the table users where I have id, username, password and profile_picture fields, and the pictures are stored in the folder uploads. So when the user login he can upload the file name in the database. The problem is that I can’t show his picture.
    Sorry but I am not so expert in php…..anyone can say me where I am wrong? Thanks.

    my controller


    function do_upload()
    {
    if($this->session->userdata('is_logged_in'))
    {
      $id = $this->session->userdata('id');
      $config['upload_path'] = './uploads/';
      $config['allowed_types'] = 'gif|jpg|jpeg|png';
      $config['max_size'] = '100';
      $config['max_width']  = '1024';
      $config['max_height']  = '768';
      $config['overwrite'] = false;
      $this->load->library('upload', $config);
          
      if ( ! $this->upload->do_upload())
      {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view("site_header");
        $this->load->view("site_nav");
        $this->load->view('upload_form', $error);
     }else
           {    
             $data = $this->upload->data();
             $file_array = $this->upload->data('file_name');
             $profile['profile_picture'] = $file_array['file_name'];
             $this->db->where('id', $id);
             $this->db->update('users', $profile);
             $this->load->view('upload_success', $data);
           }
         }else{
                  $this->load->view("site_header");
           $this->load->view("site_nav");
           $this->load->view("login_view");
           $this->load->view("site_footer");
           }   
        }
    
      
    function getImage($id)
    {
     $this->session->userdata('is_logged_in');
     $query = $this->db->query("SELECT * FROM users WHERE  id ='$id' ");
     if($query->num_rows()==0)
     die("Picture not foun!");
     else{
        $row = $query->fetch_assoc();
        $q = $row['profile_picture'];
        return true;
         }
    }

    This is my view:


    <?php echo base_url();?>uploads/

  • #2 / Apr 14, 2013 11:06am

    vash1981

    2 posts

    <?php echo base_url();?>uploads/
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases