0

I am writeing a site in php with codeigniter, the imgs i have in my imgs folder in the root directory of my site, i wrote the front page of my site and all the imgs load, the view loads, all css works fine. i made a copy the view and renamed to make the next view and when i load that view, none of the imgs load in it, it is the exact same code as the fist view and it loads fine, i dont under stand this, can u please help. i am running ubuntu 12.04, codeigniter 2.1.3 with mod_rewrite

Edit:

i left broken code with out the part that worked for the other 6 imgs

this is the code that didnt work with: code from below that fixed everything but three items:

<img src="<?php echo base_url('path/to/image.jpg'); ?>">

this is the code it did not fix

<?php 
    if(!$this->session->userdata('is_logged_in')){
        echo '<BR />';
        echo '<a href='.base_url()."main/login".'><img src="imgs/log_in_0.png" /></a>';
        echo '<BR />';
        echo '<BR />';
        echo '<a href='.base_url()."main/signup".'><img src="imgs/sign_up_0.png" /></a>';
        echo '<BR />';
    } 

?>

this css to load background:

body 
{
    background-image:url('imgs/green_tex.jpg');
}
John
  • 497
  • 2
  • 6
  • 20

1 Answers1

1

This is most likely a relative vs absolute path problem.

I am going to assume that you're calling images like this:

<img src="path/to/image.jpg">

What you should do, is call them like this:

<img src="<?php echo base_url('path/to/image.jpg'); ?>">

As a reminder, you need to have the url helper loaded for base_url() to work. I would suggest adding it to your autoload.php file.

In response to your recent edits:

echo '<a href='.base_url()."main/login".'><img src="' . base_url('imgs/log_in_0.png') . '" /></a>';

and for the CSS, you're going to have to put the path in manually, such as:

background: url(/imgs/log_in_0.png);
Brendan
  • 4,565
  • 1
  • 24
  • 39
  • correction it didnt work for the background img in the css or two items that i will post in a edit in a sec – John Dec 05 '12 at 23:15
  • Then you need to use absolute URLS. Put / in front of the url for your CSS images, or use a relative path from the css file to the image. This is not a CodeIgniter problem, but rather how you've organized (and coded) your site's front end. – Brendan Dec 05 '12 at 23:27
  • It would be helpful if you spent the time to learn the difference between relative and absolute urls, so that you don't run into this in the future: http://stackoverflow.com/questions/2005079/absolute-vs-relative-urls – Brendan Dec 05 '12 at 23:32