Php 当require_once()链接出子目录时出错

Php 当require_once()链接出子目录时出错,php,warnings,fatal-error,include-path,Php,Warnings,Fatal Error,Include Path,我正在尝试要求_once()一个位于我的根目录中的文件夹中的文件。。。我需要从根目录的另一个子文件夹中的文件中获取此文件 根 包括 include_all.php 我的 问题_history.php 这是我的/question_history.php: <?php require_once("./includes/include_all.php"); ?> 我发现以下错误: 警告: require_once(./includes/include_all.php

我正在尝试要求_once()一个位于我的根目录中的文件夹中的文件。。。我需要从根目录的另一个子文件夹中的文件中获取此文件

    • 包括

      • include_all.php
    • 我的

      • 问题_history.php
这是我的/question_history.php:

 <?php require_once("./includes/include_all.php"); ?>

我发现以下错误:

警告: require_once(./includes/include_all.php)[function.require once]: 无法打开流:中没有此类文件或目录 /Applications/XAMPP/xamppfiles/htdocs/AnswerTree2/my/question_history.php 在线3

致命错误:require_once()[function.require]:打开失败 必需。“/includes/include_all.php” (include_path='。:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear') 在里面 /Applications/XAMPP/xamppfiles/htdocs/AnswerTree2/my/question_history.php 在线3


我有点不习惯把文件放在不同的文件夹里,因为我以前只把所有的东西都放在根文件夹里。我知道这是个坏习惯。但是无论如何,希望这足够详细。

这个
/
是当前目录。试试
/includes/include_all.php

/
是当前目录。试试
/includes/include_all.php

正确的代码应该是:

<?php require_once("../includes/include_all.php"); ?>


出现错误,因为
/
要求文件位于同一文件夹中,因此您的代码要求
includes
文件夹位于
我的
文件夹中。

正确的代码是:

<?php require_once("../includes/include_all.php"); ?>


错误出现了,因为
/
要求文件位于同一文件夹中,因此您的代码将要求
includes
文件夹位于
我的
文件夹中。

还可以查看魔法常数,可能会有所帮助。例如,使用uuu DIR_uuuu可能很有用:

还可以查看魔法常数,可能会很有用。例如,使用_DIR__可能很有用:

也许PHP没有访问此文件的权限?您是否已授予他们创建文件的权限?另请参阅GeoffK建议的DIR。也许PHP没有访问此文件的权限?您是否已授予他们创建文件的权限?另见GeoffK建议的DIR。