【问题标题】:How to PHP-Include from Root of Domain?如何从域的根目录中包含 PHP?
【发布时间】:2016-02-26 18:52:16
【问题描述】:

我有一个位于www.example.com/folder/ 的file.php。

我希望该文件对位于www.example.com/include/ 的文件使用包含命令。

如果我简单地使用:

<?php include './include/footer.php';?>

它不起作用,因为它会尝试在file.php 所在的物理文件夹中搜索,而我需要它来引用我的域的根目录。

【问题讨论】:

  • 使用第二个点遍历父目录:<?php include '../include/footer.php';?>.
  • 那行得通,但我想这是考虑到我只想升一级,对吧?

标签: php include include-path php-include


【解决方案1】:

使用$_SERVER['DOCUMENT_ROOT']

这是server documentation。

当前脚本正在执行的文档根目录,在服务器的配置文件中定义。

合起来应该是这样的:

include $_SERVER['DOCUMENT_ROOT'] . "/include/footer.php";

【讨论】:

  • 这是什么意思?只需在我当前行之前使用这条确切的行吗?
  • 使用包含 $_SERVER['DOCUMENT_ROOT'] 。 "/include/footer.php";
猜你喜欢
  • 1970-01-01
  • 2012-07-10
  • 2021-07-21
  • 2023-03-20
  • 2016-08-18
  • 2011-09-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多