Subtracting path from document root in PHP
php
Solution
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
Problem
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: - Executed script is located here: root/f1/f2/f3/f4/f5/file.php. - This script includes another script located here: root/f6/file2.php 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']."/../../");`