【问题标题】:php require relative pathphp需要相对路径
【发布时间】:2012-04-21 05:53:15
【问题描述】:

当我在我的索引页面中需要任何 PHP 文件时,我看到一个错误:

我的配置文件:

define( "APP_ROOT", realpath( dirname( __FILE__ ) ).'/' );

我的包含/需要文件放置:

localhost/test/includes/

失败代码和错误:

require_once(APP_ROOT .'includes/test1.php');
require_once(APP_ROOT .'includes/test2.php');

failed to open stream: No such file or directory in C:\xampp\htdocs\test\includes\test.php on line 38

我的问题是什么?我怎样才能为任何相对路径解决这个问题。

【问题讨论】:

  • 尝试打印出APP_ROOT .'includes/test1.php'查看目录是否正确
  • 我不认为这里生成的错误表单....on line 38 上的内容是什么???
  • 第 38 行可能是包含行,因为错误是找不到文件

标签: php relative-path include-path


【解决方案1】:

看起来你的文件是从 /test/includes 调用的,所以 APP_PATH 是 C:\xampp\htdocs\test\includes\,所以你试图要求 C:\xampp\htdocs\test\includes\includes/ test1.php 等等。

回显 APP_PATH 并查看它打印的内容。

最好让所有包含相互关联,然后你只需要从 index.php 中导入一个 common.php 文件来玩游戏

【讨论】:

  • 那么你可能需要包含 app_root 。 'test/includes/test1.php' 等等
【解决方案2】:

也许realpath(dirname(__DIR__))

【讨论】:

    猜你喜欢
    • 2012-12-03
    • 2018-03-26
    • 2014-09-05
    • 2015-02-23
    • 1970-01-01
    • 2013-08-06
    • 2012-05-25
    • 1970-01-01
    • 2015-07-15
    相关资源
    最近更新 更多