When writing PHP programs, you often use include or require to include other files. However, when there are too many files included in each file, path problems will occur.
The following directory:
├Folder
│ │
│ └1.php
├Folder
│ │
│ └2.php
└index.php
Now the index.php in the root directory needs to include the 1.php file in the A folder, just use include "./A/1.php"
And 1.php in folder 1 includes 2.php in folder B, then write include "../B/2.PHP" in 1.php
But you must know that when index.php includes 1.php, compilation is performed in index.php, that is, the include in the file included in index.php is relative to index.php, then 1.php is included in index.php, then we need to find 2.php relative to index.php. As mentioned above, what is written in 1.php is include "../B/2.php". Now the compiled file is relative to the root directory of the website (that is, relative to index.php), and "../" means Then we have to go back to the upper level directory to search, so how can we find it?
I have also searched for some methods on the Internet, and the best way is to use the absolute path method. You can define a single entry file, include the files to be included, and define a constant define("__ROOT__",dirname(__FILE__));, then in the process of writing subsequent files, you only need to use the absolute method and add __ROOT__ That's it.