When using include or require to include a file, add dirname(__file__) before the file path. For example: There are currently four files a.php, b.php, c.php, and d.php. Their relationship is:
b.php (same level as the root directory)
Root directory/a. php
Root directory/c.php
Root directory/dir/d.php
Now a.php should contain b.php and c.php. The writing method is as follows:
|
include_once(dirname(__file__)."/../b.php"); include_once(dirname(__file__)."/c.php"); ?> |
include_once(dirname(__file__)."/../b.php");
include_once(dirname(__file__)."/c.php");
include_once(dirname(__file__)."/dir/d.php"); ?> |
?> If c.php contains d.php. The writing method is as follows:
include_once(dirname(__file__)."/dir/d.php"); ?> |
This method is currently The most effective way to solve path misalignment
http://www.bkjia.com/PHPjc/371453.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/371453.html
TechArticleWhen using include or require to include a file, add dirname (__file__) before the file path. For example: There are currently four files a.php, b.php, c.php, and d.php. Their relationship is: b.php (same as the root directory...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn