My current document root is this (via $_SERVER['DOCUMENT_ROOT']):
/var/www/html/clients/app/folder
I need to generate one folder up:
/var/www/html/clients/app
How would I go about doing this?
I had asked this in the past: Dynamically finding paths, is there a better way?
However, I have this scenario which doesn't work:
In file2.php, I needed the following code for this to work:
$base_path = dirname(realpath("../../../../do_not_remove.txt"));
When in theory, based on its location, it should have been this:
$base_path = dirname(realpath("../do_not_remove.txt"));
In practice, there would be a global available where this data could be passed. However, in this inherited project, there isn't thus I'm reusing this where I need it.
Update #1
Based on the answers, this seems to work great: realpath($_SERVER['DOCUMENT_ROOT']."/../../");
well you could have - $_SERVER['DOCUMENT_ROOT'] ."/../"
- even though it doesn't look too pretty
OR a slightly more propper way might be - dirname( $_SERVER['DOCUMENT_ROOT'] )
- think this should work
$path = $_SERVER['DOCUMENT_ROOT']."/../";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With