dongxiane0395 2015-10-08 20:39
浏览 16

获取当前正在执行的脚本的目录的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']));
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Matlab问题解答有两个问题
    • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架
    • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
    • ¥15 stm32的can接口不能收发数据
    • ¥15 目标检测算法移植到arm开发板
    • ¥15 利用JD51设计温度报警系统
    • ¥15 快手联盟怎么快速的跑出建立模型