Recently, when developing template functions for WordPress, I discovered that a path error would occur when directly using include ("file name") to call other PHP code snippets. The server environment has always been iis before, and similar bugs have never occurred. However, after switching to a linux server, a path calling error occurred. After searching on the Internet, I found that dirname(__FILE__) can be used when calling to solve the path error when including files under the Linux server.
In fact, the main problem comes from the site root directory problem under the linxu server. When a file is included under the linux server, its path is /home/web/. If you use the include("/filename") format directly, the actual included file path is /home/web/filename.
The complete usage method is include dirname(__FILE__) . ‘/page.php’
The file referenced by this code needs to be in the same directory as the file where the code is located. If you need to call the upper directory, you can use dirname(dirname(__FILE__)) to call the file in the upper directory.
If you encounter inclusion problems after changing the server of your website, you may wish to check whether there are any reference path errors on the website. It is recommended to use the dirname(__FILE__) method to reference files when writing PHP includes to solve reference problems in most cases.