Page 1 of 1

Get path to *included file* ?

Posted: Tue May 09, 2006 8:27 am
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

Posted: Tue May 09, 2006 8:35 am
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__);