我可以获取包含文件中最初调用的PHP文件的路径吗? [英] Can I get the path of the PHP file originally called within an included file?

查看:74
本文介绍了我可以获取包含文件中最初调用的PHP文件的路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有index.php,它存储在/home/user/public/www中,并且index.php从文件inc/app/Foo.class.php调用类Foo->bar().

Let's say we have index.php and it is stored in /home/user/public/www and index.php calls the class Foo->bar() from the file inc/app/Foo.class.php.

在这种情况下,我希望Foo类中的bar函数获得路径/home/user/public/www的保留—我不想使用全局变量,传递变量等.

I'd like the bar function in the Foo class to get a hold of the path /home/user/public/www in this instance — I don't want to use a global variable, pass a variable, etc.

推荐答案

这难道不容易让您找到正在运行的脚本的目录吗?

Wouldn't this get you the directory of the running script more easily?

$dir=dirname($_SERVER["SCRIPT_FILENAME"])

这篇关于我可以获取包含文件中最初调用的PHP文件的路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆