0
votes

I made a header view file and in that header I'm trying to echo a picture from the folder images. This images folder is outside the application folder. Also the name of the picture is logo.jpg

This is the code to echo the picture in the header.php file:

<nav class="nav-bar">
      <img class="logo" src="../../images/logo.jpg" alt="Jongeren kansrijker logo"/>
     </nav>

On another view page called home I'm including the header like this:

<?php   include_once ('templates/header.php');  ?>

When I load the home.php view page the picture does not load. It does echo the alt of the picture: alt="Jongeren kansrijker logo

What am I doing wrong here and how can I echo the logo.jpg picture from the images folder?

3
What is the path to the images dir on the server? It should be in a public directory. - Jim Wright
State clearly location of image related to FCPATH or index.php file. - Tpojka
Tip In codeigniter you don't need to use include_once for loading view codeigniter way is <?php $this->load->view('templates/header');?> - Mr. ED
Make sure you have set your base_url in config.php the use <?php echo base_url('images/logo.jpg');?> - Mr. ED

3 Answers

2
votes

First of all you should load url helper in the autoload.php which is in config folder as following.

$autoload['helper'] = array('url');

Second, you should use $this->load->view ('templates/header'); instead of including files using include_once();

Third, You should config your baseurl in config.php which is also in config folder as below(considering you are working in localhost)

$config['base_url'] = 'http://localhost/projectName/';

The above code takes you to the root of your project.

And the last point to view the image use the following code

<img class="logo" src="<?= base_url('images/') ?>logo.jpg" alt="Jongeren kansrijker logo"/>
1
votes

use an absolute path with base_url();

<img class="logo" scr="<?= base_url();?>/images/logo.jpg" />

you can set your base_url in the config.php and it should target the folder where your index.php is in (And I guess the image-folder is also there).

0
votes

This usually means your src attribute is wrong. Remember that the value should be the path from the root of your website as it is managed as a separate request by the browser.

I imagine in your case you're actually looking for the following:

<img class="logo" src="/images/logo.jpg" alt="Jongeren kansrijker logo"/>

TLDR: The image is fetched by the browser so you shouldn't use the path from header.php.