javascript - PHP : Is it possible to include a file from a sibling directory?

标签 javascript php html xampp

您好,在我的主目录中,我有 2 个子目录:subDir_AsubDir_B。在subDir_A中有一个名为file_a.php的文件。在subDir_B中我有一个文件file_b.php。在file_b.php中我想包含file_a.php。有可能吗?我正在使用 Xampp。 enter image description here

最佳答案

使用 4 个函数之一可以轻松完成此操作。

includeinclude_oncerequirerequire_once,请参阅此文档 http://php.net/manual/en/function.include.php (我不会对此进行扩展,因为它是非常基本的 PHP 功能)

您应该按照以下方式进行包含。

# you could use any of the other keywords as well.
include __DIR__ . '/../subDir_A/file_A.php'; 

使用了魔术常量__DIR__,因为它将考虑相对于它所调用的文件的引用。如果您不这样做,而只是执行include '../subDir_A/file_A.php';如果您在其他地方包含 file_B.php,它可能不起作用,因为它将相对于调用它的父文件。

关于javascript - PHP : Is it possible to include a file from a sibling directory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43164753/

相关文章:

javascript - 类(class)员工

javascript - 从 Json 加载 FabricJS

php - 分配中的 "Object of class ... could not be converted to string"

asp.net - 使用 asp.net 控件创建无序列表?

html - 使用 CSS 用同级元素填充空白区域

html - 如何修复背景位置的错误?

javascript - 无法使用纯 JavaScript 加载 ag-grid

javascript - Jquery-步骤 : jquery key events not working

PHPRedis - 时间()不起作用

javascript - gldatepicker 更改提交