I was wondering if one method was better than the other. I have been using the $_SERVER
method to point to the current directory but is this method better than the realpath(dirname(_FILE_))
method or is there any difference?
PHP $ _SERVER ['DOCUMENT_ROOT'] vs realpath(dirname(_FILE_))
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- douxing5199 2014-05-25 09:20关注
The
$_SERVER[ 'DOCUMENT_ROOT' ]
variable returns a server setting. Specifically it returns:The document root directory under which the current script is executing, as defined in the server's configuration file.
The
realpath( dirname( __FILE__ ) )
function will return the path of the folder that the current script is actually residing.One is returning the value of a server setting and the other evaluates to a file's path. In some cases, the values will be the same but you should be aware of the difference between the two.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报