【问题标题】:As soon as I try to include a file inside a folder, my relative paths break?一旦我尝试在文件夹中包含文件,我的相对路径就会中断?
【发布时间】:2012-05-30 02:46:05
【问题描述】:

只是想知道我在这里做错了什么。我一直在设置一个linux开发环境。如果我这样做:

include 'test.php';

效果很好。

如果我将 test.php 文件移动到名为 test 的文件夹中并执行以下操作:

include 'test/test.php';

失败了。怎么回事?

我也试过了:

include '/var/www/site/test/test.php';
include '/test/test.php';
include '../test/test.php';

等等,没有运气。

【问题讨论】:

  • 也许你正在使用某种 url 重写?
  • 权限可能有误
  • 请给出错误。语法似乎正确。
  • 在您尝试包含的文件中,放置 echo getcwd(); 并让我们知道当前工作目录是什么。
  • 'test/' 位于根文件夹中,而 'test.php' 位于当前(包括调用/启动)文件夹中。

标签: php ubuntu include include-path


【解决方案1】:

包含您包含文件的文件夹(以及您要求 php 引擎访问的任何其他嵌套文件夹)应该设置其可执行标志。

在 linux 终端中:

chmod a+x /var/www/site/test

检查权限:

ls -l /var/www/site | grep "test"

【讨论】:

    【解决方案2】:

    你试过require('test/test.php'); 吗?

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 2015-10-08
      • 2016-02-27
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      相关资源
      最近更新 更多