【问题标题】:Required_once file not routing correctlyRequired_once 文件未正确路由
【发布时间】:2017-05-17 19:15:19
【问题描述】:

我正在尝试包含一个文件,我已经在我现在遇到问题的确切页面上成功地完成了该文件。由于某种原因,以下调用不起作用。三种方法我都试过了。

require_once ("required_files/page-count.php");
require_once 'required_files/page-count.php';
include_once("required_files/page-count.php");

最初我将文件夹命名为php 而不是required_files,我收到了错误消息,所以我更改了它,认为 php 可能是一个受限文件夹名称。现在,由于我已更改它,它似乎仍在搜索我以前的名称,但它不在我的代码中。

错误:

警告:require_once(php/page-count):无法打开流:第 40 行的 /home4/public_html/account/required_files/page-count.php 中没有这样的文件或目录

致命错误:require_once():无法在 /home4/public_html/account/required_files/page-count 中打开所需的 'php/page-count' (include_path='.:/opt/php55/lib/php')。 php 在第 40 行

主文件是我试图在其中包含文件 page-count.php 文件的文件。

有谁知道发生了什么以及为什么这不起作用?

required_files 文件夹中:

【问题讨论】:

  • 您为accountpublic_html 显示的文件夹列表?
  • @wogsland 这是给account的。
  • 我知道我似乎仍在呼吁php/post-count.php,但我不是,这就是我如此困惑的原因。
  • page-count.php 第 40 行有什么内容?
  • @wogsland 现在它是被注释掉的代码行。不知道为什么它正在阅读它。 //require_once ("required_files/page-count.php");。我未注释的行是include_once("required_files/page-count.php"); .......我在页面上的任何地方都没有php/post-count.php,甚至没有注释掉。

标签: php apache include require-once


【解决方案1】:

/opt/php55/lib/php 是默认路径。如果在其他任何地方都找不到,它会在那里尝试。

我会像这样回显 test.php:

这会告诉你它是 /home4/publc_html/ 还是 /home4/public_html/account 作为你的根目录。

使用 $_SERVER['DOCUMENT_ROOT'] 是一种很好的形式,因为您的主机可能会将您移动到具有不同主文件夹的新服务器。这样它总是会解析到正确的位置。

【讨论】:

  • 在 test.php 中
猜你喜欢
  • 1970-01-01
  • 2013-06-29
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 2020-05-29
  • 2021-04-27
  • 1970-01-01
  • 2018-11-26
相关资源
最近更新 更多