php require 中的文件路径
我继承了一些代码:
include('../cfg/db_setup.php');
require('./fpdf/fpdf.php');
我知道 ../cfg 意味着从当前目录开始,然后向上一层并向下进入 cfg 目录。 ./fpdf 是什么意思?我从未见过在文件路径中使用单点斜杠,并且似乎无法在我们服务器上的任何位置找到 fpdf 目录,但代码正在运行,所以显然它就在那里。
I've inherited some code:
include('../cfg/db_setup.php');
require('./fpdf/fpdf.php');
I know that ../cfg means start in the current directory, then go up one level and down into the cfg dir. What does the ./fpdf mean? I've never seen a single dot slash used in a file path, and can't seem to find the fpdf directory anywhere on our server, but the code is working so apparently it's there somewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只是一个注释。
相对路径不相对于当前的 include_path。
相对路径,例如 .或 ../ 相对于当前工作目录。如果您在 CGI 或命令行上运行脚本,或者某个脚本被另一个目录中的另一个脚本包含,则工作目录会有所不同。
因此,理论上不可能在不知道上下文的情况下确定这些路径指向哪里:P
可以肯定的是,如果 PHP < 5.3:
如果 PHP >= 5.3:
Just a note.
Relative paths don't are relative to the current include_path.
Relative paths, such as . or ../ are relative to the current working directory. The working directory is different if you run a script on CGI or command line or if a script is included by another script in another directory.
Therefore theoretically is not possible to be sure where these paths are pointing to without to know the context :P
To be sure, if PHP < 5.3:
If PHP >= 5.3:
.
被定义为当前文件夹。因此,如果 PHP 脚本位于
/path/to/script/
,那么第二条语句将查找/path/to/script/fpdf/fpdf.php
.
is defined as the current folder.So, if the PHP script is located at
/path/to/script/
, then the second statement will look for/path/to/script/fpdf/fpdf.php
./ 是当前目录。 ./fpdf/ 应该与包含文件位于同一路径上,或者位于 php include_path 之外的某个位置。
./ is the current directory. ./fpdf/ should be on the same path as the including file, or somewhere on the off the php include_path.
./
- 这意味着在当前路径中./
- this means in the current path