Relative path problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jjl
Forum Newbie
Posts: 13
Joined: Wed May 14, 2008 12:31 am

Relative path problem

Post by jjl »

If I include a file from another page and the included file references another file, the path to that file is relative to the page that called the include not the included file.

Is there any way I can make the file paths relative to the include page?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Relative path problem

Post by Weirdan »

Code: Select all

 
include dirname(__FILE__) . '/path/relative/to/the/including/file.php';
 
I believe this save a couple of lstats as well - thus a bit faster.
jjl
Forum Newbie
Posts: 13
Joined: Wed May 14, 2008 12:31 am

Re: Relative path problem

Post by jjl »

Thanks, but then when I call it from another directory it will fail from that one because it will be relative to the other file that called it not the current one. The file will be called from many different directories, the problem is because using a call like include or require for some reason behave by assuming the called file is in the same as the calling file.
I am new at this but I cannot see a reason why the call cannot be to the exact file position rather that to a relative file position which is going to vary. Why do people dislike exact file poisitions like includ (http:/www/hereitis.com/now/you/have/FoundTheFile.ok.).
Post Reply