2017-10-09 116 views
0

我[根] /includes/helpdesk/pipe.php与此代码:如何在管道脚本中使用相对路径(../)?

#!/opt/cpanel/ea-php55/root/usr/bin/php 
<?php 
require_once("pipeprocess.php"); 

在相同的位置在第一线pipeprocess.php我包括在相同的位置仍然另一个文件:helpdesk.php

然后在第一行[根] /includes/helpdesk/helpdesk.php我有:

require_once ("../../config.php");

的config.php是在[根],这就是为什么我有两次.. /../,helpdesk.php可以正常工作t访问,但如果通过管道命令设置在cPanel中运行pipe.php,我会得到一个反弹错误,该配置。 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工作正常? pipe不接受../或../../作为路径的一部分吗?或者是否有EasyApache4问题?我做了几个测试,并注意到这是因为../作为包含路径的一部分。 Pipe/EasyApache4有问题吗?

回答

2

如果您使用__DIR__,根据您当前正在运行的脚本文件的文件夹在哪里?

在PHP 5.3.0中,你可以使用这样的事情:

require_once (__DIR__ . "/../../config.php"); 
+0

感谢。工作。 –