Include directory throws an error

It’s a shame of course to ask a question, but I’m already tired of these misunderstandings: the test folder is located in the root directory. I call the function includein mods/mod1/md.php:

include("../test/test.php");

writes an error and returns only to the modsdirectory and looks for the testfolder there. How many of these damned dots do you need to put? After all, they mean, if there are 2 of them, then 2 directories back. What am I doing wrong? Or is it only possible with $_SERVER['DOCUMENT_ROOT']?


Answer 1, authority 100%

..is a return to the parent directory.
You call include (it’s better to use require_once) in mods/mod1/md.php
those. in the directory mods/mod1/, you need to go to the root and select another directory test

respectively, relative to the file md.phponce ..it will be a transition to the parent directory of the folder mod1i.e. modsyou need to go even higher to the parent directory of the modsfolder – so we use ..again, i.e. we already have two transitions ../../– now we are in the root directory, from here we go to the desired folder and the script in it /test/test.php,

total we got ../../test/test.php

in general, of course, it’s better to use $_SERVER["DOCUMENT_ROOT"], which gives us the path to the root directory right away and move on from it, i.e. the path becomes absolute, this gives you the ability to move the file from which you call includeto any other directory without having to change the path of the called file.