Reputation: 4172
I call my PHP file from a deeply nested folder because my code is structured in modules.
I tried this:
define('__ROOT__', dirname(__FILE__).'../../../');
echo __ROOT__;
This gives me:
/var/www/virtual/myvirtualservername/mywebsite.com/modules/Dialog/Feedback../../
I cannot just use:
$_SERVER['DOCUMENT_ROOT']
That gives me:
/var/www/virtual/myvirtualservername/html
which is also the wrong folder.
Unfortunately it doesn't work and I don't have an error log on my server so I can't debug the internal server error. Requested that now from my provider.
In summary, my question is how to reach the folder I want,
/var/www/virtual/myvirtualservername/mywebsite.com/
?
Upvotes: 0
Views: 139
Reputation: 72560
I think your issue is you are not adding a slash at the start of your paths. Directory values are returned without trailing slashes, e.g. /var/www
Modifying your first line to this should work:
define('__ROOT__', __DIR__.'/../../../mywebsite.com');
echo __ROOT__;
I replaced dirname(__FILE__)
with __DIR__
as mentioned in the comments. Also note that __ROOT__
does not have a trailing slash, so you would add that when putting your file in, e.g.
include __ROOT__ . '/file.php';
I'm not exactly sure what the deal is with your document root though. It looks like the public part of the site is in html
but the PHP code is in a directory mywebsite.com
alongside that.
Upvotes: 2
Reputation: 547
I don't know...perhaps you can do a 'string replace' if you want it to be exact, something like the following:
define('__ROOT__',str_replace("/modules/Dialog/Feedback","",dirname(__FILE__)));
Something like this should yield the result you want.
Upvotes: 0