是否更喜欢在网站中使用 $_SERVER['DOCUMENT_ROOT'] ?
您认为最好在网站的 include
语句中使用 $_SERVER['DOCUMENT_ROOT']
吗?是否到处都支持,没有任何问题?
Do you think it is preferred to use $_SERVER['DOCUMENT_ROOT']
in website's include
statements? Is it supported everywhere without any problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
许多框架使用
dirname(__FILE__)
根据已知文件(通常是index.php)计算出应用程序路径。在Zend Framework中,它们使用以下内容来定义应用程序路径,然后使用该路径应用程序中的所有位置:
Many frameworks use
dirname(__FILE__)
to work out the application path based on a known file, usually the index.phpIn the Zend Framework, they use the following to define the application path, which is then used everywhere in the app:
我个人更喜欢相对路径:
include("../../some/other/path.php")
每当我创建一个目录时,我确切地知道我的目录树是如何设置的,而且它并不是否有文档根目录或其他任何可用的东西都没关系。此外,在某些情况下,
$_SERVER['DOCUMENT_ROOT']
可能不起作用(例如,我见过人们在 IIS 上遇到问题)。I personally prefer relative paths:
include("../../some/other/path.php")
Whenever I create a directory, I know exactly how my directory tree is setup, and it doesn't matter whether there is a document root or anything else available.Furthermore, there are some cases where
$_SERVER['DOCUMENT_ROOT']
may not work (eg, I have seen people have issues with it on IIS).