Home >Backend Development >PHP Tutorial >Solve PHP relative directory problem_PHP tutorial

Solve PHP relative directory problem_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 14:52:571013browse

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 misalignmenthttp://www.bkjia.com/PHPjc/371453.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371453.htmlTechArticleWhen 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