Get path to *included file* ?

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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Get path to *included file* ?

Post by Chris Corbyn »

Hi,

Okie dokie! getcwd() gets me the current directory of a script. Great.

Now, what if that script was included by another script? It then gets the directory which the parent script is in right? (or does it? Hmm maybe I should check before posting :oops:).

My question is: How can I have an included file independently determine where it was inlcuded from?

i.e.

files:

Code: Select all

./foo/
    parent.php
    bar/
./foo/bar/
        included_file.php
Now if ./foo/parent.php include()'s ./foo/bar/included_file.php, included_file.php will report that it's in ./foo not ./foo/bar . Does anybody have a clue what I'm rambling on about? :P
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Out comes that big wet slippery.... fish, to hit me in the face again.

I love posting my probs here only for the answer to pop into my head :P

Code: Select all

echo dirname(__FILE__);
Post Reply