Discover php include relative path, include the articles, news, trends, analysis and practical advice about php include relative path on alibabacloud.com
Previously seen, many frameworks, mostly rarely used relative path inclusions. and generally many do PHP Web site, like to use relative path. Think so, no matter where the directory is put. As long as the other directory relationship is consistent.
In a logical sense, the relative path of the directory is less than the absolute path. Like what.. The/admin/is significantly less than the directory traversed by c:/wamp/www/cms/templates/admin/.
Scenario: When using include (_once), require
Talk about the relative path problem in PHP and the use of absolute path, php absolute path
Problem description
First, let's take a look at the directory structure of our example and the content of the three files.
A. php
B. php
C/d. php
The d.
Include and require absolute paths and relative paths in PHP, too derequire
When writing a PHP program, you often need to use include or require to include other files. However, if there are too many files in each file, a path problem occurs.
The
Php command line (cli) to execute the relative path of the PHP script file. Php command line (cli) to execute the relative path of the PHP script file. the working directory of the Execution Environment (getcwd () is the relative path of the php
a.php:: include "b.class.php";
Suppose that there is a relative path in the member method of b.class.php;
such as:./1.php __file__ and so on;
Will these relative paths be relative to the source file or relative to the a.php;
I use __file__ and.
1 absolute, relative, and indeterminate paths
Relative path
A relative path refers to a path that begins with a.
./a/a.php (relative to current directory)
.. /common.inc.php (relative superior directory),
Absolute path
Absolute path is
Summary of require and include path issues in PHP, Requireinclude
1 absolute path, relative path, and indeterminate path
Relative path
A relative path refers to a path that begins with a.
./a/a.php (相对当前目录) ../common.inc.php (相对上级目录),
Absolute
Require and include path issues in PHP, Requireinclude
1 absolute path, relative path, and indeterminate path
Relative path
A relative path refers to a path that begins with a.
Copy the Code code as follows:./a/a.php (relative to current directory).
When you require,include a file in PHP, it's mostly a relative path, and it's a very frustrating problem. Example: (site root) ├ folder ││ │└1.php ├ folder ││ │└2.php └INDEX.P HP Problem: In 1.php by include (". /b/2.php ") to introduce 2.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.