Closed Thread Icon

Preserved Topic: Get calling directory? Pages that link to <a href="https://ozoneasylum.com/backlink?for=21178" title="Pages that link to Preserved Topic: Get calling directory?" rel="nofollow" >Preserved Topic: Get calling directory?\

 
Author Thread
butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 12-27-2001 03:37

Say I have a header.inc file that is used by pages in many other directories. Is there a way for me to tell which directory the page is from that is calling the header.inc file? I'm trying to avoid having to put the header file in every directory that calls it because I have to hard code file references in it.

I want to do this in PHP btw.

Thanks
-Butcher-

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 12-27-2001 09:26

try
dirname(__FILE__);

that returns the directory of the current file. (ie, not the one the user requested, but whatever one is being parsed. very handy for includes...).

so long

Tyberius Prime

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-27-2001 10:28

Actually, since you need to find the folder where the file that's calling header.inc file is located, you'll need to use this:

dirname($PHP_SELF);

Predefined constant __FILE__, which Tyberius Prime mentioned will return complete filename of the currently parsed file and if you put it in header.inc it will return complete filename of that include file, and not the one that called it...

BTW You can also use getcwd() function to get current working folder...


jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 12-27-2001 17:40

Nice Typerius. Actually I noticed most of the variables dealing with the file ($REQUEST_URI, $SCRIPT_NAME, etc.) are for the requested file, not the included file. I hadn't yet needed to reference the included filename (especially since it can just be hard-coded into the file), but that is a handy tip nonetheless.

-jiblet

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 12-27-2001 19:08

Your awesome as always mr.maX

Thanks TP, it's not what I need right now, but as jiblit says, a great one to file away for later use.

-Butcher-

« BackwardsOnwards »

Show Forum Drop Down Menu