On 13/09/2021 22:09, Bo Berglund wrote:
__DIR__ will change depending on the included file it's executed from,
but so too will paths relative to the current if you construct a path
On Mon, 13 Sep 2021 21:30:18 +0100, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
On 13/09/2021 21:17, Bo Berglund wrote:
On Mon, 13 Sep 2021 20:36:35 +0100, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
THen seemingly all worked, but only until a call was made to a php file at a
deeper location which also included this file...
Have you looked at __DIR__ ?
Yes, I have tested this php file located in the htdocs/ dir:
echo "Including: " .dirname($_SERVER['DOCUMENT_ROOT'],1)."/php/logindata.php";
echo "<br>Mail sender= " . $mailsender ;
echo '<br>Dir= ' . __DIR__ ;
echo "<br>DocRoot= " . dirname($_SERVER["DOCUMENT_ROOT"],1) . "/";
The output was this:
The strange thing is that even though I have set include_path according to the
selected solution in this stackoverflow thread:
it does not pick up the logindata.php file where $mailsender is defined.
If I move the test php file into /php then it picks up the information since it
is in the same dir.
Note that __DIR__ and dirname($_SERVER['DOCUMENT_ROOT'],1) return completely
It really seems very strange that they have removed this function without
supplying a new version...
They might show different paths, it all depends on the main script being
run (autoloaders are your friend here). But you can use it to generate
paths using some basic string concatenation (and some file methods if
you want some better error case handling).
However, my main goal was to be able to use includes across the server so php
files in different locations could use the same set of utilities by including
them with the correct path.
So since this obviously does not work I have to start calculating relative paths
from every place I have put the php files, like:
And what happens if such a file in turn needs an include, is it relative to the
original php file called or is it relative to the file which makes the include?
But going back to your original problem, are you sure that
$_SERVER['DOCUMENT_ROOT'] doesn't work? I've just tested on a PHP &.2
system, and it does exist and points to the document root of the