【问题标题】:include_once(../../config.php): failed to open stream: No such file or directoryinclude_once(../../config.php):打开流失败:没有这样的文件或目录
【发布时间】:2018-08-30 06:01:26
【问题描述】:

我的文件路径如 >>

/config.php
/fold_1/fold_2/functions.php
/fold_1/myfile.php

functions.php 包含 >>

include_once("../../config.php");
function addition($x,$y){return($x+$y);}
function substraction($x,$y){return($x-$y);}

myfile.php 包含 >>

include_once("fold_2/functions.php");
call addition(2,3);

但它会给出类似 >>

的警告
include_once(../../config.php): failed to open stream: No such file or 
directory 

我知道原因就像当我在myfile.php 中包含function.php 时,它会将function.php 的所有代码替换为myfile.php,然后运行function.php 的代码,所以它无法找到config.php 文件../../config.php

但我不知道是否有任何解决方案(解决方案意味着更改 php.ini 中的一些变量值或类似的) 来克服这个问题,以便它可以运行functions.php 的代码首先和之后它将映射到myfile.php

【问题讨论】:

    标签: php apache xampp wamp


    【解决方案1】:

    尝试像这样使用:

    include_once $_SERVER['DOCUMENT_ROOT']. '/path/to/config.php';
    

    有时 PHP 和服务器更喜欢完整的绝对路径而不是 ../../ - 我通常使用 $_SERVER 来修复

    【讨论】:

    • 是的,你说得对,这对我来说真的很有效,谢谢你,先生。你真的有两个拇指吗?酷似我国一位演员“hrithik roshan”也有。
    • @Stranger 没问题,很高兴我能帮上忙 :)
    猜你喜欢
    • 2018-03-26
    • 2022-10-16
    • 2016-07-10
    • 2019-12-12
    • 2018-03-01
    • 2013-10-27
    • 2013-01-24
    • 2018-12-01
    • 1970-01-01
    相关资源
    最近更新 更多