realpath(dirname(__FILE__)) returning empty string

Hi,

I'm using PHP 4.4.7. When I define a constant as

define("SITE_ROOT_DIR", dirname(__FILE__));

the result is the value ".". The real directory path should be "/home/
myaccount/web". So I tried

define("SITE_ROOT_DIR", realpath(dirname(__FILE__)));

on the advice of another, but now I'm getting an empty string. Any
ideas how to overcome this? I'd prefer not to hard code paths because
my development server path is different.

Thanks, - Dave
laredotornado [ Sa, 30 Juni 2007 23:18 ] [ ID #1756433 ]

Re: realpath(dirname(__FILE__)) returning empty string

On Sat, 30 Jun 2007 14:18:37 -0700, "laredotornado [at] zipmail.com"
<laredotornado [at] zipmail.com> wrote:

>Hi,
>
>I'm using PHP 4.4.7. When I define a constant as
>
>define("SITE_ROOT_DIR", dirname(__FILE__));
>
>the result is the value ".". The real directory path should be "/home/
>myaccount/web". So I tried
>
>define("SITE_ROOT_DIR", realpath(dirname(__FILE__)));
>
>on the advice of another, but now I'm getting an empty string. Any
>ideas how to overcome this? I'd prefer not to hard code paths because
>my development server path is different.
>
>Thanks, - Dave

Which version of PHP are you using because, acording to the PHP
manual,

__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 whereas in older versions it
contained relative path under some circumstances."

__FILE__ could be returning something like ./somescript.php instead of
an absolute directory and therefore dirname() would only return ".".

If this is the case, try $_SERVER['SCRIPT_FILENAME']
--
Brendan Gillatt
www.brendangillatt.co.uk
GPG: 0x6E265E61
Brendan Gillatt [ So, 01 Juli 2007 20:16 ] [ ID #1756871 ]
PHP » alt.php » realpath(dirname(__FILE__)) returning empty string

Vorheriges Thema: [ANN] Web testing tools selection in Methods & Tools Summer 2007 issue
Nächstes Thema: Re: I got something big and rock hard this weekend....