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__)."/dir/d.php"); ?> |
include_once(dirname(__file__)."/dir/d.php"); |