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/