简体   繁体   中英

How can I display an image from my database to a view page in CodeIgniter?

I want profile pictures from users to be displayed on the profile pages of the users. (I'm still a beginner with codeigniter)

The db row where the pictures are stored: profiel_foto The folder where the pictures are in: upload

I tried to do it like this: Profile picture: <?php echo $_SESSION['profiel_foto']; ?><br> Profile picture: <?php echo $_SESSION['profiel_foto']; ?><br>

But that doesn't work with pictures.

I am able to load pictures like this:

<img src="<?php echo base_url(); ?>upload/1498736939jeremy.jpg">

But thats not how I want to load it. I want to load profile pictures by using the profiel_foto column

Make sure that $_SESSION['profiel_foto'] contains the user image name

And Embed the file name in img tag like this

<img src="<?php echo base_url(); ?>upload/<?php echo $_SESSION['profiel_foto']; ?>">

Note :

1st : your error seems your not setting session index like profiel_foto

2nd : Make sure that session library loaded

You do this from within config/autoload.php.

 $autoload['libraries'] = array('session');

Or you can load the session library on each page like this

$this->load->library('session');

You need to get the profile pic from table and show it on profile. You can do something like below (as i am not sure what and where you are missing the logic) In controller you can write like below:

$data['profilePic'] = $this->db->query("Your query to user table")->row()->profiel_foto;
$this->load->view('view file', $data);

And in View

<img src="<?php echo base_url(); ?>upload/<?php echo $profilePic?>">

I am assuming you are storing image name in table with column 'profiel_foto'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM