首先:对不起标题。如果你可以弥补它,请这样做,因为我真的不知道如何命名我的问题。也就是说,周围很可能有重复,但我想我需要克服这个问题,只是不知道要搜索什么......
基地不是我做的。它主要是用 HTML 编写的,但包含用 PHP 完成的,我真的不喜欢它的制作方式。但这与我在这里要问的问题无关。
这里描述的文件包含的内容比这里写的要多,但这里的问题是
当需要文件 A 需要文件 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