获取PHP项目的根目录路径 [英] Get Root Directory Path of a PHP project
本文介绍了获取PHP项目的根目录路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的PHP项目中有此文件夹结构. (如eclips中所示)
I have this folder structure in my PHP project. (this is as shown in eclips)
-MySystem
+Code
+Data_Access
-Public_HTML
+css
+js
+Templates
-resources
当我尝试此代码时
echo $_SERVER['DOCUMENT_ROOT']
输出是
D:/工作区
D:/workspace
如何在不对文件夹名称进行硬编码的情况下获取系统RootDirectory的路径(MySystem
)?
How can I get the path to RootDirectory of the system (MySystem
), without hardcoding the Folder Name?
推荐答案
对于 PHP> = 5.3.0 尝试
PHP 魔术常数.
__DIR__
并使您的路径相对.
对于 PHP< 5.3.0 试试
dirname(__FILE__)
这篇关于获取PHP项目的根目录路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文