Forum Moderators: coopster

Message Too Old, No Replies

Getting absolute path name of resource file

         

thesheep

12:26 pm on Jul 10, 2004 (gmt 0)

10+ Year Member



How can I get the absolute path name of a file that I refer to within a script?

I have a text file stored above the document root. The script defines a variable like this:

$data_file = '../../data.txt';

When I call the script from another page somewhere else from within the website structure of course the relative filename for the data file is wrong.

All I can think of is to get the directory I'm currently in using dirname($_SERVER['PHP_SELF']) and strip off two layers using regular expressions. But isn't there a simpler way? Thanks.

coopster

2:51 pm on Jul 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, thesheep!

$data_file = realpath [php.net]($_SERVER [php.net]['DOCUMENT_ROOT'] . '../../data.txt');

thesheep

2:59 pm on Jul 10, 2004 (gmt 0)

10+ Year Member



Thanks very much. I'll try that.