Old __FILE__ functionality without resolved symlinks?

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
dancing dragon
Forum Newbie
Posts: 8
Joined: Sun Aug 17, 2008 4:57 am
Location: bed

Old __FILE__ functionality without resolved symlinks?

Post by dancing dragon »

How can I get the relative path of an included file from inside the include, without the symbolic links being resolved?

The __FILE__ constant used to do this. It is now fixed to give the absolute path. But is there another way to get the old functionality?

http://us2.php.net/manual/en/language.c ... efined.php
__FILE__
The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Old __FILE__ functionality without resolved symlinks?

Post by ghurtado »

Why do you want the relative path?
dancing dragon
Forum Newbie
Posts: 8
Joined: Sun Aug 17, 2008 4:57 am
Location: bed

Re: Old __FILE__ functionality without resolved symlinks?

Post by dancing dragon »

There is a piece of software that, in order to have several instances of it, has to be installed multiple times. I am trying to make it so that multiple installations are actually symbolic link "directories" all pointing to the same code base. Then each "installation" can have its own config file in the parent directory of each symbolically linked "directory".

The software comes with the functionality that it looks in the parent directory (of an included file) for a config file. I want to try a multiple installation hack by altering just this one little piece of code that looks for the config file in the parent directory to instead make it look for the config file in the parent of the symbolic link if the "directory" is actually a symbolic link. Otherwise with one copy of the code base in one actual location accessed by different symbolic link "directories", the different "installations" would actually be looking at the same config file.

Does that make sense? I am trying to do a multiple installation hack with making the smallest and cleanest amount of changes to the original code.
dancing dragon
Forum Newbie
Posts: 8
Joined: Sun Aug 17, 2008 4:57 am
Location: bed

Re: Old __FILE__ functionality without resolved symlinks?

Post by dancing dragon »

Okay, I found a thread on another forum where someone was trying to do something similar:

__FILE__ and symbolic links
http://objectmix.com/php/305013-__file__-sym-links.html

The original poster has a really short description of a solution he came up with. I am wondering if someone here can help me decipher this:
I explode('/',__FILE__);
I then loop backwards through the array prepending a "relative path"
with the current explosion value.. until
realpath($_SERVER['DOCUMENT_ROOT'].'/'.$rel_path) == __FILE__
Post Reply