Reputation: 507
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');
}
Upvotes: 0
Views: 626
Reputation: 4565
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);
Upvotes: 1