如何在管道脚本中使用相对路径 (../)?
How to have relative path (../) in a pipe script?
我有 [root]/includes/helpdesk/pipe.php 代码:
#!/opt/cpanel/ea-php55/root/usr/bin/php
<?php
require_once("pipeprocess.php");
在第一行 pipeprocess.php 的相同位置,我包含了另一个仍在相同位置的文件:helpdesk.php
然后在 [root]/includes/helpdesk/helpdesk.php 第一行我有:
require_once ("../../config.php");
config.php 在 [root] 中,这就是为什么我有两次 ../../,helpdesk.php 可以直接访问,但是如果 运行 pipe.php 通过 cPanel 中的管道命令设置,我收到了配置的弹跳错误。 php 未找到:
PHP Warning: require_once(../../config.php): failed to open stream:
No such file or directory in
/home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line
21
Warning: require_once(../../config.php): failed to open stream: No
such file or directory in
/home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line
21 PHP Fatal error: require_once(): Failed opening required
'../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php')
in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on
line 21
Fatal error: require_once(): Failed opening required
'../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php')
in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on
line 21
直接访问 helpdesk.php 工作正常,为什么我会收到此管道错误?管道不接受 ../ 或 ../../ 作为路径的一部分吗?还是 EasyApache4 有问题?我做了几次测试并注意到这是因为 ../ 作为包含路径的一部分。 pipe/EasyApache4 对此有问题吗?
根据您当前 运行 脚本文件所在的文件夹,如果您使用 __DIR__
怎么办?
从 PHP 5.3.0 开始,您可以使用这样的东西:
require_once (__DIR__ . "/../../config.php");
我有 [root]/includes/helpdesk/pipe.php 代码:
#!/opt/cpanel/ea-php55/root/usr/bin/php
<?php
require_once("pipeprocess.php");
在第一行 pipeprocess.php 的相同位置,我包含了另一个仍在相同位置的文件:helpdesk.php
然后在 [root]/includes/helpdesk/helpdesk.php 第一行我有:
require_once ("../../config.php");
config.php 在 [root] 中,这就是为什么我有两次 ../../,helpdesk.php 可以直接访问,但是如果 运行 pipe.php 通过 cPanel 中的管道命令设置,我收到了配置的弹跳错误。 php 未找到:
PHP Warning: require_once(../../config.php): failed to open stream: No such file or directory in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line 21
Warning: require_once(../../config.php): failed to open stream: No such file or directory in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line 21 PHP Fatal error: require_once(): Failed opening required '../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line 21
Fatal error: require_once(): Failed opening required '../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line 21
直接访问 helpdesk.php 工作正常,为什么我会收到此管道错误?管道不接受 ../ 或 ../../ 作为路径的一部分吗?还是 EasyApache4 有问题?我做了几次测试并注意到这是因为 ../ 作为包含路径的一部分。 pipe/EasyApache4 对此有问题吗?
根据您当前 运行 脚本文件所在的文件夹,如果您使用 __DIR__
怎么办?
从 PHP 5.3.0 开始,您可以使用这样的东西:
require_once (__DIR__ . "/../../config.php");