【发布时间】:2023-03-25 23:55:02
【问题描述】:
我在根目录有一个文件 index.php:
<?php
require_once "./include/common.php";
?>
和包含文件夹中的common.php文件:
<?php
require_once "globalConfig.php";
?>
将 globalConfig 文件与 common.php 放在同一文件夹中。树文件夹为:
xxx/index.php
xxx/include/common.php
xxx/include/globalConfig.php
index.php 运行正常。但是,如果我将文件 common.php 更改为:
<?php
require_once "./globalConfig.php";
?>
PHP 显示一个警告,它找不到 globalConfig.php 文件。有什么区别?我认为在“./”的情况下,最外部的包含文件(index.php)会在其当前目录中找到 globalConfig.php。
【问题讨论】:
-
另请参阅stackoverflow.com/questions/1395909/…、stackoverflow.com/questions/3429780/include-and-path-problem,以及搜索“php 包含路径”的许多其他问题:)
标签: php include require-once