Step #1: Understand two concepts:
Current working directory: the directory of the current php file
Current processing file directory: the directory of the file that the current php file refers to .
Step #2: Example:
// 目录1下的a.php代码 <?php header("Content-Type:text/html;charset=UTF-8"); require_once'../b.php'; echo "这里是a"; ?> //php_test根目录下的b.php代码,想调用和他同目录的c.php <?php require_once'c.php'; echo "这里是a上一级的b"; ?> //php_test根目录下的c.php代码 <?php echo "这里是和b同一目录的c"; ?> //目录1下的c.php代码 <?php echo '这是和a同目录的c'; ?> //结果如下 这是和a同目录的c 这里是a上一级的b 这里是a
You need to call php.exe to run websocket in the project,
when you use Quote include('.. /lib/core/tool.php');, an error will be reported, and the error prompts that the corresponding file cannot be found. This problem involves the two concepts mentioned in the first step. websocket.php is the file in the current working directory, and tool.php is the file in the reference directory.
Step
#4: Solution:
gives a string containing the full path of the file and returns a directory name with the file name removed. .
__FILE__: Predefined variables. Full path and file name of the file. If used within an included file, returns the name of the included file.
define('ROOT_PATH',dirname(__FILE__)); Generally used as the root path.
Two:
You can also use a clumsy method to provide files in different file paths according to different systems.
The above introduces the PHP file system-directory, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.