Table of Contents
回复讨论(解决方案)

require目录

Jun 23, 2016 pm 01:57 PM
require Table of contents

osadmin的目录如下

注意
index.php在uploads目录下,
init.inc.php在uploads/include目录下
config.inc.php在uploads/include/config目录下

index.php:
require ('./include/init.inc.php');

init.inc.php:
require 'config/config.inc.php';

按理说访问index.php页时,寻找config.inc.php页的路径应为uploads/config/config.inc.php,是一个错误路径,但为什么实际运行确能找到?各位能解释下是怎么找到的吗。

难道解析这种既不是绝对路径,又不是相对路径的的路径,还有什么基情。

(补充)include_path:‘.;C:\php\pear’


回复讨论(解决方案)

init.inc.php:
require 'config/config.inc.php';

init.inc.php里面不是包括了config.inc.php 么,当然能找到啦。

php不是参照入口文件的路径吗?也就是说 在找config.inc.php时应该是按“uploads/config/config.inc.php”这个路径找,但显然这个路径不存在,存在的是“uploads/include/config/config.inc.php”。难道不是这样?

require 'config/config.inc.php';
不是在 init.inc.php 中执行的吗?
所以既然只有 uploads/include/config/config.inc.php 存在,当然就加载他了

你#2的描述是正确的
如果你有 uploads/config/config.inc.php 文件,那么这个文件将被优先加载
也就是说,你可以用这种方法干预应用系统的行为

下面是用我的伪代码描述require请求文件的处理,看对否:
相对路径:前面带./或者../的路径,如'./include/init.inc.php'
伪相对路径:前面不带./或者../且又不是绝对路径的路径,如'config/config.inc.php'
当前工作目录:web环境下,即入口文件所在目录

if(path为绝对路径){    file_path=path;}else if(path为相对路径){    file_path=conbine(当前工作目录,path);}else{    //伪相对路径    dir_list=include_path;    dir_list.add(当前工作目录);    dir_list.add(调用语句所在目录);    foreach(dir_list as dir){        temp_path=conbine(dir,path);        if(temp_path存在){            file_path=temp_path;            return;        }    }}
Copy after login

访问index.php页时
require 'config/config.inc.php';
其实生效的是
file_path=conbine(调用语句所在目录,path)
这里调用语句所在目录,即init.inc.php文件所在目录,从而正确找到文件。

是的,是这样的

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to insert a table of contents in Google Docs How to insert a table of contents in Google Docs Apr 13, 2023 pm 08:16 PM

Whether it is an article, paper or tutorial, the main highlight of any document is the title and of course the table of contents. It describes the outline structure of the document so that users can get to where and what they expect to read from the document. It's also a best practice to add a table of contents to most documents to make them look more professional. Today, everything happens online and people use Google Docs to create most documents. Many users are still not sure how to insert or add a table of contents in google docs. Therefore, we come up with this article to explain how to create or insert a table of contents in Google Docs. How to Insert a Table of Contents in Google Docs Step 1: Click here to visit Google Docs Online. Step 2: If

vue3+vite: How to solve the error when using require to dynamically import images in src vue3+vite: How to solve the error when using require to dynamically import images in src May 21, 2023 pm 03:16 PM

vue3+vite:src uses require to dynamically import images and error reports and solutions. vue3+vite dynamically imports multiple images. If vue3 is using typescript development, require will introduce image errors. requireisnotdefined cannot be used like vue2 such as imgUrl:require(' .../assets/test.png') is imported because typescript does not support require, so import is used. Here is how to solve it: use awaitimport

Use java's File.isDirectory() function to determine whether the file exists and is a directory type Use java's File.isDirectory() function to determine whether the file exists and is a directory type Jul 24, 2023 pm 06:57 PM

Use Java's File.isDirectory() function to determine whether a file exists and is of directory type. In Java programming, you often encounter situations where you need to determine whether a file exists and is of directory type. Java provides the File class to operate files and directories. The isDirectory() function can help us determine whether a file is a directory type. The File.isDirectory() function is a method in the File class. Its function is to determine the current File

The glob() function in PHP is used to find files or directories The glob() function in PHP is used to find files or directories Nov 18, 2023 pm 06:17 PM

The glob() function in PHP is used to find files or directories and is a powerful file operation function. It can return the path of a file or directory based on a specified pattern match. The syntax of the glob() function is as follows: glob(pattern, flags) where pattern represents the pattern string to be matched, which can be a wildcard expression, such as *.txt (matching files ending with .txt), or a specific file path. flags is an optional parameter used to control the function

PHP function introduction—rename(): Rename a file or directory PHP function introduction—rename(): Rename a file or directory Jul 25, 2023 pm 12:10 PM

PHP function introduction—rename(): Renaming files or directories Introduction: In PHP, the rename() function is used to rename files or directories. It provides an easy way to change the name of a file or directory. Whether it is a single file or an entire directory, you can use this function to perform a rename operation. The renaming process can be easily accomplished by specifying the name of the source file or directory and the target name. Syntax: boolrename(string$source,str

What are the uses of require? What are the uses of require? Nov 27, 2023 am 10:03 AM

Usage of require: 1. Introduce modules: In many programming languages, require is used to introduce external modules or libraries so that the functions they provide can be used in the program. For example, in Ruby, you can use require to load third-party libraries or modules; 2. Import classes or methods: In some programming languages, require is used to import specific classes or methods so that they can be used in the current file; 3. Perform specific tasks: In some programming languages ​​or frameworks, require is used to perform specific tasks or functions.

How to check if a directory is empty in Linux How to check if a directory is empty in Linux Mar 20, 2023 am 10:17 AM

How to check whether the directory is empty in Linux: 1. Enter the Linux terminal; 2. By executing "res=`ls -A $dir` if [ -z $res ]; then echo "$dir ..."else echo "$ The dir..."fi" method can determine whether the directory is empty.

How to read the catalog when reading on WeChat How to view the catalog How to read the catalog when reading on WeChat How to view the catalog Mar 30, 2024 pm 05:56 PM

The mobile version of WeChat Reading App is a very good reading software. This software provides a lot of books. You can read them anytime, anywhere with just one click to search and read them online. All of them are officially authorized and different types of books are neatly arranged. Sort and enjoy a comfortable and relaxing reading atmosphere. Switch the reading modes of different scenarios, update the latest book chapters continuously every day, support online login from multiple devices, and batch download to the bookshelf. You can read it with or without the Internet, so that everyone can discover more knowledge from it. Now the editor details it online Promote the method of viewing the catalog for WeChat reading partners. 1. Open the book you want to view the catalog and click in the middle of the book. 2. Click the three lines icon in the lower left corner. 3. In the pop-up window, view the book catalog

See all articles