How do you include a file that is more than 2 directories back. I know you can use ../index.php to include a file that is 2 directories back, but how do you do
But be VERY careful about letting a user select the file. You don't really want to allow them to get a file called, for example,
../../../../../../../../../../etc/passwd
or other sensitive system files.
(Sorry, it's been a while since I was a linux sysadmin, and I think this is a sensitive file, from what I remember)
.. selects the parent directory from the current. Of course, this can be chained:
../../index.php
This would be two directories up.
if you are using php7 you can use dirname function with level parameter of 2, for example :
dirname("/usr/local/lib", 2);
the second parameter "2" indicate how many level up
dirname referance
../../../includes/boot.inc.php
You can do ../../directory/file.txt - This goes two directories back.
../../../ - this goes three. etc
../ is one directory, Repeat for two directories ../../ or even three: ../../../ and so on.
Defining constants may reduce confusion because you will drill forward into directories verses backwards
You could define some constants like so:
define('BD', '/home/user/public_html/example/');
define('HTMLBD', 'http://example.com/');
When using 'BD' or my 'base directory' it looks like so:
file(BD.'location/of/file.php');
define(); reference