Jump to content

Loading image from php include


Muteking

Recommended Posts

My first post, here. I'm a newbie in PHP. I'm stuck in a simple problem

I have my index.php in the base folder which includes right.php.

This right.php has to load an image (base folder/img) but it's in another folder called 'includes'(base folder/includes). I cannot figure out what value I have to assign to my $baseUrl variable, in order to jump back to the base folder.

Here is right.php:

 

<? $baseUrl = "../" ;?>
<div class = "right">
<h1> Rifrazione news </h1>
<hr>
<?
echo '<img src="'.$baseUrl.'/img/face.png" width="200"  alt="news"/>';
?>
<p class = "rightp">bla bla </p><br>

</div><!--end of right-->

Link to comment
https://forums.phpfreaks.com/topic/282277-loading-image-from-php-include/
Share on other sites

When dealing with URLs in your HTML, the only(ish) thing that matters is what shows up in the address bar of the browser.

 

The easiest way to not care about that is to use absolute URLs: a leading slash. If the image is in the includes/ folder of your website (and your website isn't in a subfolder like http://www.example.com/subfolder) then

news

The problem is that the image in not in the includes folder.

Here's the effect, anyway, even if I try alernate code with leading slash

 

<div class = "right">
<h1> News </h1>
<hr>
<?
echo '<img src="/img/face.png" width="200"  alt="News"/>';
?>
<p class = "rightp"> Bla blalalal</p><br>
</div><!--end of right-->

 

 

effect_zpsfc66b8bd.jpg

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.