dongxiane0395
dongxiane0395
2015-10-08 20:39

获取当前正在执行的脚本的目录的URL

Ok, no, this is not a dupe or at least it is not answered. I want to know the url to the currently executing script's directory.

Any answer involving $_SERVER['REQUEST_URI'], et al is (likely) off topic.

I have a script at /blah/blah/public_html/foo/bar/thescript.php. This script is included by other scripts. My browser is not at http://domain.com/foo/bar/thescript.php.

What I want is /foo/bar or http://domain.com/foo/bar

I came up with:

$dir = str_replace($_SERVER['DOCUMENT_ROOT'],'', __DIR__);

It works, ok. Just checking for other solutions.

Ok, yep, its a dupe. here is another way. (very much the same as what i came up with

$dir = substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT']));
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐