PHP:工作文件在包含后不查找其他文件


PHP: A working file doesn't find other files after inclusion?

首先:对标题表示抱歉。如果你能编造一些东西来代替它,请这样做,因为我一开始真的不知道如何命名我的问题。也就是说,很可能有重复的,但我认为我需要克服这个东西,只是不知道要搜索什么…

基地不是我做的。它主要是用HTML编写的,但包含了PHP,我真的不喜欢它的制作方式。但这和我想问的问题越来越不相干了。

这里描述的文件包含的内容比这里写的要多,但这里的问题是
当文件A需要文件B而文件B需要很多文件时,文件B找不到它要找的文件

假设我有这样一个目录树:

| - Project
+--- lower.txt
| -- Stuff
| ---- Case
+------ index.php
+------ upper.php
| -- Gallery
+---- main.php
+---- config.php
+---- miscfunc.php
+---- css.php

项目'东西' ' index . php:

<?php include("./upper.php");?> ...
<?php include("../../lower.txt");?>

项目' '中' upper.php东西:

<?php require_once("../../Gallery/main.php"); ?>

项目' ' main.php画廊:

<?php namespace Gallery;
...
// I'm just trying to debug something here... :
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- //
$PathToScan = "./"; // Scan current directory, will point to /Project/Stuff/Case/
function ScanFolder($path) {
    $Array = array();
    if ($dir = @opendir($path)) {
        while (($file = readdir($dir)) !== FALSE) {
            $Array[] = $file;
        }
        printf("Current directory: %s<br/>'n", dirname(__FILE__));
        printf("document_root: %s<br/>'n", $_SERVER["DOCUMENT_ROOT"]);
        printf("Scan directory: %s<br/>'n<br/>'n", $path);
        var_dump($Array);
    }
}
ScanFolder($PathToScan);
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- //
require_once("./config.php"); // These files are also in Gallery namespace
require_once("./miscfunc.php");
require_once("./css.php"); ...
...
?>

所以…当我执行Project'Stuff'Case'index.php我得到:

Current directory: C:'xampp'htdocs'Project'Gallery
document_root: C:/xampp/htdocs
Scan directory: ./
array(4) { [0]=> string(1) "." [1]=> string(2) ".." [2]=> string(9) "index.php" [3]=> string(7) "upper.php" }
Warning: require_once(./config.php) [function.require-once]: failed to open stream: No such file or directory in C:'xampp'htdocs'Project'Gallery'main.php on line 44
Fatal error: require_once() [function.require]: Failed opening required './config.php' (include_path='.;C:'xampp'php'PEAR') in C:'xampp'htdocs'Project'Gallery'main.php on line 44

现在为什么会发生这种情况,以及我如何在不移动任何文件的情况下使其工作,最好不要破坏main.php?

我最终改变了

require_once("./filename.php");

require_once(__DIR__ . "/filename.php");


我还在想如果不是这样的话……