PHP require()对relative或full不起作用


php require() does not work with relative or full

我对require()命令有一个奇怪的问题,它根本不工作,给了我一个奇怪的错误。是的,我百分之百确定我的路径是正确的我尝试使用相对路径和完整路径,以及使用include(), include_once(), require(), require_once(),但无济于事。我测试了文件的存在,它确实存在。这对我来说毫无意义!我还没有看到其他人有同样的问题在论坛上,我也尝试使用全局变量,如$_SERVER["DOCUMENT_ROOT"]和其他路径,但这仍然不适合我。

过程如下:HTML按钮-> ajax调用"addcomments.php" ->页面需要"ajax.php"->错误

addcomments.php页面:

//set path
$path = "g:/appserv/www/y4project/scripts/php/funcs/";
//check directory 
print_r(scandir($path));
//check if php file exists
if(file_exists($path."ajax.php"))
    echo "######### IT EXISTS!!! ##########";
else echo "@@@@@@ NO! @@@@@@@@";
//require it
require($path."ajax.php");

错误:

Array ( 
    [0] => . 
    [1] => .. 
    [2] => account.php 
    [3] => ajax.php 
    [4] => main.php 
    [5] => service.php ) 
######### IT EXISTS!!! ##########
Warning: require(1) [function.require]: failed to open stream: No such file or directory in G:'AppServ'www'y4project'scripts'AJAX'addcomments.php on line 10
Fatal error: require() [function.require]: Failed opening required '1' (include_path='.;C:'php5'pear') in G:'AppServ'www'y4project'scripts'AJAX'addcomments.php on line 10

我也尝试了相对路径,如"../php/funcs/ajax.php",同样的问题。scandir()file_exists()都找到了,但require()失败了!

非常感谢您的帮助!

编辑

我只是测试了它是肯定的,需要它从不同的测试页面,并使用了一个函数,它工作了,但仍然不能从"addcomments.php"页面得到AJAX调用。

另一个编辑

我还检查了PHP require_once()require()的文档,我仍然看不到问题!

它可能是某种类型的路径错误或安全措施,其中AJAX调用的脚本不能调用其他脚本等等?但这没有意义吗?
我也没有在文档中读到任何有关的内容。
我甚至试着要求HTML页面,但仍然不能工作。

我迷路了. .

您可以尝试这样使用:

require dirname(__DIR__) . "/php/funcs/ajax.php";