Page 1 of 1
Files used by include library not displayed!
Posted: Mon Nov 11, 2002 10:39 am
by Oneinchpunch
Ok here is my problem:
I have a php page in a directory: "x/y/z/page.php"
This page refers to content in its current directory, which works fine, and I have also included a library file the line for this is as follows:
include ("../../layout.php");
i.e. layout.php resides in "x/" directory.
The functions in the library work ok, however, files referenced by it, such as images, are not displayed when page.php is run. I presume this is because the script is still looking in "x/y/z/...." for these resources rather than the path relative to the library script in "x/".
How do I resolve this?
Please help!
Re: Files used by include library not displayed!
Posted: Mon Nov 11, 2002 11:10 am
by jason
Oneinchpunch wrote: I presume this is because the script is still looking in "x/y/z/...." for these resources rather than the path relative to the library script in "x/".
The script has nothing to do with images. The browser is looking in x/y/z/ for the images you references. You simply have to point the browser to the right images to use in relation to the page it's loading.
Posted: Mon Nov 11, 2002 12:56 pm
by Oneinchpunch
That's what I said, but I need a way of telling the library file to look for files relative to itself rather than the Page.php location.
I have some other pages on the site that are located in the same directory as the library file, and these all find the image files ok, but not when page.php is in another location.
I hope that makes sense?!
Posted: Mon Nov 11, 2002 3:54 pm
by Daedalus
A good rule of thumb that i allways go by is use
$_SERVER['DOCUMENT_ROOT'] then your relative path.
like
include($_SERVER['DOCUMENT_ROOT'] . "/x/layout.php");
Then when you reference files your giving an absolute path rather then a relative path to what your looking for and your scripts will not get messed up because it's included or what have you.
Posted: Mon Nov 11, 2002 7:51 pm
by Oneinchpunch
That's a good tip, I've changed my code accordingly, but it still doesn't solve the problem I have. It may help to show you the actual pages:
All the pages on the site have a standard layout which is defined through functions in a file called "layout.php" and stored in the root directory. This contains tables formatting and relative paths to images etc. This file gets included in each of my pages so all I have to do is call 'page_start()' for example and the title & menu template will be output.
A typical page looks like this:
http://members.lycos.co.uk/thelogsite/index.php
Now I put the same page in a subdir and change the include line:
include($_SERVER['DOCUMENT_ROOT'] . "layout.php");
Look what happens:
http://members.lycos.co.uk/thelogsite/g ... /index.php
Clearly the functions do work as the page is partially formatted, but all the images are missing (other than the two referenced as http://....).
As I said before I think this is due to the layout.php script looking for files relative to index.php where it is being called...
"
http://members.lycos.co.uk/thelogsite/g ... hingpairs/"
...rather than the root (which it should be) where layout.php is located:
"
http://members.lycos.co.uk/thelogsite/"
How do I make it look for files relative to the root dir?
Sorry to drag this out but I'm new to PHP and getting really wound up by this problem. If you can shed some light it would be greatly appreciated.
Posted: Mon Nov 11, 2002 7:58 pm
by volka
the missing image is
created by the tag
Code: Select all
<img name="menu" src="images/menu.gif" ...
this has nothing to do with the script anymore but how the client (browser) treats this information.
The url of the current page is
http://members.lycos.co.uk/thelogsite/g ... /index.php
the src-property contains a relative url, so the browser will request the document
http://members.lycos.co.uk/thelogsite/g ... s/menu.gif
if you want to change this you have to provide another src-property pointing to the correct location.
since the image is at
http://members.lycos.co.uk/thelogsite/images/menu.gif you probably want to set src="
/images/menu.gif"
Posted: Mon Nov 11, 2002 8:12 pm
by Oneinchpunch
Of course! That makes perfect sense now, thanks for spelling it out to me.

its a bit of a pain in the butt though, I'm just gonna have to figure another way round it.