2

我在主文件夹中有一个文件 a.php,两个文件 b.php 和 c.php 在 child_folder 中。三个文件的内容如下

a.php
<?php
require 'child_folder/b.php';
?>

b.php (within child folder)
<?php
require 'c.php';
require 'child/c.php';
?>

c.php (within child folder)
<?php
echo 'this is c file<br>';
?>

当我运行 a.php 时,它会回显以下输出

这是c文件

这是c文件

用文件 b 调用文件 c 的正确方法是什么,它应该被称为 wrt a 文件或 wrt b 文件..?

4

1 回答 1

0

最好的方法是在“include”中给出文件的绝对路径。这不会与嵌套目录产生任何混淆,您还可以将它从一个文件复制并粘贴到另一个文件。

define("CURRENT_PATH", dirname(__FILE__));   // This defines the path as the directory the file is in.

include(CURRENT_PATH . "/path/to/file");
于 2013-07-04T20:10:28.340 回答