Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about php includes ? 1

Status
Not open for further replies.

maverick

MIS
Apr 21, 1999
193
0
0
US
Hey guys,

Is there any way to get a php files to reference images from it's own location rather them the location it's included from ?
for instance; my index file has an include to a file in a dir called pages and the included file has images that are in a dir called images that is in the dir called pages, but the images will not show unless I reference them to pages/images/etc... even though the file is in pages,
I dislike this about php, if I used frames this would not be an issue!

I will explain further if need be

Thanks in advance !



+--------------------------+
| "Hacker by Heart" |
| Yahoo! : saenzcorp |
+--------------------------+
 
Frames and PHP aren't related. Feel free to have your PHP code generate frames, if you like. If I understand your question, this is really a general web issue.

You want to have a PHP page, say Any relative tags which are written by that file will be relative to the root. If you use then the tags are relative to dir2.

If index.php includes something from another directory, then that include file may write tags also. But, from the browser's perspective, they're all coming from the same file. The browser doesn't know that the included file is in a different directory.
 
use absolute urls and you won't have a problem.

Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
The location of the included file is relative to the file which actually includes the file.

So if you are viewing a file which is in dir 'pages'(i assume that you are using relative path to images), the images can be seen correctly but if you are viewing 'index.php', the path of the images will be images/someimage.gif and not pages/images/someimage.gif,
so you can either use absolute path to iamges or use 'pages/images/' in file which is included in index.php. (If you are not displaying this file somewhere).

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
This is really a HTML question. The fact that the HTML was created by PHP is merely circumstancial. href attributes in HTML documents can be:
1. absolute, e.g. 2. site root specific, e.g. /images/img01.png
3. relative to the document, e.g. ../images/img01.png
4. referenced further by a basehref tag
 
this sounds interesting...
can you elaberate on
4. referenced further by a basehref tag

thanks

+--------------------------+
| "Hacker by Heart" |
| Yahoo! : saenzcorp |
+--------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top