2015-10-08 20:39


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

What I want is /foo/bar or

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']));
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答