Solve PHP relative directory problem_PHP tutorial

WBOY
Release: 2016-07-21 14:52:57
Original
987 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template