Jump to content

Loading image from php include


Muteking
Go to solution Solved by mac_gyver,

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
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
Link to comment
Share on other sites

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

Edited by Muteking
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.