如何找到调用文件的位置?
我试图找到 php.ini 中显示的文件的位置。
我有一个小文件,可以包含在根目录或任何文件夹中的任何文件中。
我需要打印出的位置。
长解释:我的配置文件是 config.php 位于网站的根位置,即 localhost/site1/test/。它包含print $_SERVER['SCRIPT_NAME']
。它被根位置中的index.php 包含,也被根位置的includes 文件夹中的database.php 包含。
我得到两个不同的结果:
localhost/site1/test/,当我在index.php中包含config.php时
localhost/site1/test/includes,当我包含 config.php 时 database.php
我想在这两种情况下都获得 localhost/site1/test 。那么可以选择什么$_SERVER['SCRIPT_NAME']
I am trying to locate the location of file being displayed in php.
I have a small file which can be included by any file wither from root or from inside any folder.
i need to print out the location of the.
for long explanation: my config file is config.php located in root location of website i.e localhost/site1/test/. It contains print $_SERVER['SCRIPT_NAME']
. it is being included by index.php in root location and also by database.php inside the includes folder of root.
I get two different result:
localhost/site1/test/, when i include config.php in index.php
localhost/site1/test/includes, when i include config.php in
database.php
I would like to get localhost/site1/test in both cases. So what can be the choice instead $_SERVER['SCRIPT_NAME']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
dirname(__FILE__)
(如果使用 PHP >= 5.3,则尝试__DIR__
)。http://php.net/manual/en/language.constants.predefine.php
Try
dirname(__FILE__)
(or__DIR__
if using PHP >= 5.3).http://php.net/manual/en/language.constants.predefined.php
试试这个:
print_r($_SERVER)
您一定会在该数组中找到您要查找的内容。更新:
Try this:
print_r($_SERVER)
you will surely find what you are looking for in that array.Update: