【问题标题】:trouble with require_once failed to open stream: No such file or directoryrequire_once 的问题无法打开流:没有这样的文件或目录
【发布时间】:2018-01-21 03:19:45
【问题描述】:

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

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.phpin 终端的内容来检查文件路径是否存在,并且返回很好,当我在第 6 行获取当前工作目录时,它返回 @987654324 @,我假设它正在定义我的根文件夹。

不知道如何解决这个问题,如果有人对方法有任何想法,我很想听听他们的意见,因为我的 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";

我也证实这不是权限问题。

【问题讨论】:

  • 试试require_once realpath(dirname(__FILE__)) .'/core_services/logging.php';
  • 这种方法不走运,它返回相同的错误,只是更新尝试的文件路径。

标签: php require require-once


【解决方案1】:

尝试指定完整路径:

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

【讨论】:

  • 不幸的是,这些方法都不起作用。只有更新的文件路径才会出现同样的错误。
  • 您使用的是 Windows 还是 Linux?
  • Mac 实际上,使用 XAMPP
  • 不确定,但它可能是另一种文件格式/名称吗?我的意思是,一切看起来都不错
猜你喜欢
  • 2011-07-04
  • 2017-06-16
  • 1970-01-01
  • 2011-05-27
  • 1970-01-01
  • 2015-02-25
  • 1970-01-01
  • 2016-07-24
  • 1970-01-01
相关资源
最近更新 更多