php and include-statements with images

J

Jan Faerber

Hello!

php is better than frames. So I tried something with php.
Now I have this problem that when I have an index.php file
with an image like <img src="images/pic.png">, I have this code
in an /includes folder e.g. a file header.php with:

'
....
<img src="images/pic.png">
....
'

and I make in the index.php file a statement like this:

'
....
<?php
include header.php;
?>
....
'

I don't know if the syntax is 100% correct now but anyway
I want to do the same with a file in another location -
/en/index.php ... so, here the location of the images is not
the same relative to the location of the 'main' index.php file.
The browser can not find the images because they are
found now in '../images/' and not in '/images/'.

So my question is:
How can I use the same include files
but with different levels of folders when I want to use
only one folder for images for instance.
First I solved this problem by using absolute paths
in the 'header.php' file e.g. <img src="http://213.47.90.11/images/pic.png">
but that seems not to be the best way it can be done.

ty
 
J

Jan Faerber

Toby said:
Use domain-less absolute paths:
<img src="/images/pic.png">

ty
-
at the moment it works. But I asked because before it didn't work.
I don't know why.
 
J

Jan Faerber

<veröffentlicht & per Mail versendet>

Jan said:
ty
-
at the moment it works. But I asked because before it didn't work.
I don't know why.

No, it does not work.
Only if I have the header.php or buttons.php in my root directory.
That is fine.
Wy does it not look up the /includes folder?
Wouldn't that be more systematic?
And here I will get the problem again: the images are located now
in ../images.
 
D

Dave Patton

Hello!

php is better than frames.

Apples are better than dogs.
Your statement doesn't make sense, but PHP is nice,
and Frames are evil ;-)
How can I use the same include files
but with different levels of folders when I want to use
only one folder for images for instance.
First I solved this problem by using absolute paths
in the 'header.php' file e.g. <img
src="http://213.47.90.11/images/pic.png"> but that seems not to be the
best way it can be done.

Either use absolue paths such as:
<img src="/images/pic.png">
or, for more flexibility, use a "config file":
- every PHP script does an include of your site's
"config file", in which you define string variables
that contain the filesystem path(for when you are
using filesystem-related function) or URL path(for
when you are dealing with URLs) for various directories.
- use the appropriate "config file variable" in your
scripts, rather than hardcoding any paths
For example, if my "confif file" has been included, and
it contains someting like:
$MYSITE_URL_ROOT = "/"; // location of main site HTML/PHP files
$MYSITE_URL_IMAGES = "{$MYSITE_URL_ROOT}images/"; // location of images
then in the above example you would use:
<img src="<?=$MYSITE_URL_IMAGES?>pic.png">
 
D

Dave Patton

Are you implying that dogs are evil? ;)

I was going to say "Apples are better than oranges",
but I didn't want to get on the bad side of the
citrus growers ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top