亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home php教程 php手冊(cè) Problems with include and require absolute paths and relative paths in PHP

Problems with include and require absolute paths and relative paths in PHP

Oct 19, 2016 am 10:19 AM

When writing PHP programs, you often use include or require to include other files. However, when there are too many files included in each file, path problems will occur.

The following directory:

(website root directory)
Folder
│ │
│ └1.php
Folder
│ │
│ └2.php
└index.php

Now the index.php in the root directory needs to include the 1.php file in the A folder, just use include "./A/1.php"

And 1.php in folder 1 includes 2.php in folder B, then write include "../B/2.PHP" in 1.php

But you must know that when index.php includes 1.php, compilation is performed in index.php, that is, the include in the file included in index.php is relative to index.php, then 1.php is included in index.php, then we need to find 2.php relative to index.php. As mentioned above, what is written in 1.php is include "../B/2.php". Now the compiled file is relative to the root directory of the website (that is, relative to index.php), and "../" means Then we have to go back to the upper level directory to search, so how can we find it?

I have also searched for some methods on the Internet, and the best way is to use the absolute path method. You can define a single entry file, include the files to be included, and define a constant define("__ROOT__",dirname(__FILE__));, then in the process of writing subsequent files, you only need to use the absolute method and add __ROOT__ That's it.

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

PHP Tutorial
1488
72