require_once的问题无法打开流:没有这样的文件或目录

时间:2017-08-12 21:11:02

标签: php require require-once

尝试打开我接手的项目的索引文件时出现以下错误:

Warning: require_once(core_services/logging.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/index.php on line 7

Fatal error: require_once(): Failed opening required 'core_services/logging.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/index.php on line 7

错误引用的代码如下所示:

7 require_once "core_services/logging.php";
8 $logger=new syslog_class(__FILE__,LOG_DEBUG);

我检查确保文件路径存在,方法是定义它并回显它以及终端中logging.php的内容,并返回正常,当我在第6行获得当前工作目录时,它返回/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com,我假设是定义我的根文件夹。

不确定如何解决这个问题,如果有人对方法有任何想法,我很乐意听到他们,因为我的PHP有点生疏,缺乏wordpress背景。

编辑:到目前为止我尝试过的方法

require 'core_services/logging.php';
require '/core_services/logging.php';
require './core_services/logging.php';
require '../core_services/logging.php';
require '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';
require realpath(dirname(__FILE__)) .'/core_services/logging.php';
require(__DIR__"/../core_services/logging.php");

require_once 'core_services/logging.php';
require_once '/core_services/logging.php';
require_once './core_services/logging.php';
require_once '../core_services/logging.php';
require_once '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';
require_once realpath(dirname(__FILE__)) .'/core_services/logging.php';
require_once __DIR__"/../core_services/logging.php";

我还验证了它不是权限问题。

1 个答案:

答案 0 :(得分:0)

尝试指定完整路径:

require './core_services/logging.php';
//OR
require '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';