View Single Post

  #7 (permalink)  
Old 02-26-2008
AnrDaemon
 
Posts: n/a
Default Re: Determine folder a script is running in.

Greetings, Guillaume.
In reply to Your message dated Friday, February 22, 2008, 11:22:59,

>>>> What is the most reliable method to determine the folder a script is
>>>> running in?
>>>>
>>>> I was looking at the globals in $_SERVER but all the variables also
>>>> listed the actual file the script was running in.
>>> How about dirname($_SERVER['SCRIPT_FILENAME'])?

>>
>> This is in no way close to trusted information about actual directory script
>> running in.

> [...]
>> Solution is
>> $cwd = realpath('.');
>> It working fine under Windows. Hope it is true for other systems.


> Still not.


> >>> I was looking at the globals in $_SERVER but all the variables also
> >>> listed the actual file the script was running in.


> As stated, SCRIPT_FILENAME uses the script the user is *currently*
> running even if the instruction was written in a second file, somewhere
> else, that is just included.
> Unfortunately, realpath('.') has the same behavior.


> dirname(__FILE__) is a solution, it returns the directory of the scripts
> that implements it, not the one that was called, since __FILE__
> specify the filename of the script using it.


Question was

>>>> What is the most reliable method to determine the folder a script is
>>>> running in?


not "directory the script located in".

Go realize difference. Or read my previous answer carefully.

> if C:\www\test.php includes C:\www\test\test2.php, and you add those
> commands to test2.php:
> echo $_SERVER['SCRIPT_FILENAME'] => "C:/www"
> echo realpath('.') => "C:\www"
> echo dirname(__FILE__) => "C:\www\test"


> It often bugged me in the past :)





--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

Reply With Quote