关于获取根目录解决方法

WBOY
Release: 2016-06-13 10:26:13
Original
964 people have browsed it

关于获取根目录
我觉得$_SERVER['DOCUMENT_ROOT']可以
怎么有人用的是这种方法呢
define('_MUSIC_ROOT_', str_replace('\\','/',substr(dirname(__FILE__), 0, -3)));

------解决方案--------------------
$_SERVER['DOCUMENT_ROOT'] 需要在服务器配置文件中定义,不确定是否有配置权限的情况下 还是用第二种方法吧
------解决方案--------------------
是的,在大多数情况下 $_SERVER['DOCUMENT_ROOT'] 就可以了
但你应该注意到:在某些服务器配置中 $_SERVER['DOCUMENT_ROOT'] 无值,或不正确
另外当你的项目被放在子目录中时 $_SERVER['DOCUMENT_ROOT'] 也不能正确反映项目的根

所以可以这样理解:
$_SERVER['DOCUMENT_ROOT'] 是网站的根路径
define('_MUSIC_ROOT_', str_replace('\\','/',substr(dirname(__FILE__), 0, -3)));
是项目的根路径
------解决方案--------------------
关键在最后一个-3你可以不减试试,或是-5
你把地址输出出来立马就明白了
这是放你配置文件里的一个代码,得到的是该文件绝对路径,减去几就是把尾部文件夹名去掉,如果你没放在根的话,减到根为止,别的地方调用都是对的了

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!