"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:c8*******************@news.demon.co.uk...
"Virgil Green" <vj*@obsydian.com> wrote in message
news:R8***************@newssvr23.news.prodigy.com. .. "Duncan Bayne" <dh*****@ihug.co.nz> wrote in message
news:f8*************************@posting.google.co m... Hi All,
I have a PHP program that includes files from the 'include' directory
relative to the path that translates to the HTTP root of the site.
This is '/var/www/html' on the server, and '~/username/public_html' on
my dev box.
My question is - is there any way to resolve the path to a file,
something like:
include GetBasePath() . '/include/top.inc';
where GetBasePath() returns '/var/www/html' or
'~/username/public_html' depending upon which server it's running?
I've looked through the manual & the FAQ but found nothing.
include($_SERVER['DOCUMENT_ROOT'] . '/include/top.inc');
- Virgil
Why do you think you need such a thing? The include_path option in the
PHP.INI file may contain several entries, therefore it may not be possible
to resolve it to a single path. Besides, PHP will automatically scan ALL
the entries in the include_path when attempting to resolve an include()
statement. You do NOT need to specify any directory name on an include()
statement as PHP will examine all the directory names on the include_path
setting.
(top-posting 'corrected' for my reading pleasure)
I don't. The OP might. In addition to the include_path, the include will
look in the same directory as the currently executing file.
Personally, I prefer to have just the . in the include_path along with any
other system-level includes I might need and then use relative filenames.
But, as Chris pointed out, you might not always have access to the php.ini.
You might not even be able to change include_path via .htaccess if your host
has implemented phpsuexec (or phpsu, or whatever variant). Then, you are
supposed to use a private php.ini... but I haven't tried or bothered. I
still prefer relative file paths.
- Virgil