php file system - directory

WBOY
Release: 2016-07-29 09:07:58
Original
873 people have browsed it

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&#39;../b.php&#39;;     
    echo "这里是a"; 
?>
//php_test根目录下的b.php代码,想调用和他同目录的c.php
<?php require_once&#39;c.php&#39;;
    echo "这里是a上一级的b"; 
?>
//php_test根目录下的c.php代码
<?php echo "这里是和b同一目录的c"; 
?>
//目录1下的c.php代码
<?php echo &#39;这是和a同目录的c&#39;;  
?>
//结果如下
这是和a同目录的c
这里是a上一级的b
这里是a
Copy after login
Step #3: Actual case:

You need to call php.exe to run websocket in the project,

php file system - directory

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:

One:

string dirname(string path)

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.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!