PHP 在非专用服务器上使用 dirname(__FILE__) ?
我想做的是在配置文件中定义一个常量变量:
DEFINE("PATH", dirname(__FILE__) . "/");
这样,当我想“包含”或重定向时,我可以这样做:
include(PATH . "filename.php");
或者
header("location: " . PATH . "logout/php");
但是当我尝试对 PATH 进行回显时,我得到以下结果:
/home/myDOMAIN/public_html
我错误地声明了常量吗? (说实话,我从 WordPress 配置文件中复制了该代码)
What I trying to do is to define a constant variable in a config file:
DEFINE("PATH", dirname(__FILE__) . "/");
So that, when I want to "include" or redirect, I could do this:
include(PATH . "filename.php");
or
header("location: " . PATH . "logout/php");
But when I try doing an echo of PATH, I get this result:
/home/myDOMAIN/public_html
Am I declare the constant wrongly? (To be honest, I copy that code from Wordpress config file)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:
试试这个:
更多信息:
http://php.net/manual/en/reserved.variables.server.php
Update:
Try this:
More Info:
http://php.net/manual/en/reserved.variables.server.php
__FILE__
魔术常量包含一个文件系统 路径,而不是 URL。您需要创建两个不同的常量,例如用于包含的FS_ROOT
和用于URL 的WEB_ROOT
。在许多情况下,$_SERVER 数组中已有一个可以为您提供帮助的内置值。运行
print_r($_SERVER)
来找出答案。The
__FILE__
magic constant contains a file system path, not a URL. You'd need to create two different constants, e.g.FS_ROOT
for includes andWEB_ROOT
for URLs.In many cases, you already have a builtin value in the $_SERVER array that can help you. Run
print_r($_SERVER)
to find out.我想这是你在服务器端的路径。
I guess this is your path on the server side.