php - 如何在嵌套文件夹中包含 php 文件
问题描述
我是 php 新手并面临最初的问题:)。
我的目录结构如下:
site
index
homepagesections.php
assets
css
style.css
config
db.php
include
header.php
index.php
在根文件夹中的 index.php 中,我需要包含 header.php 文件,其中包括 config/db.php 和 assets/css/style.css。
我已经尝试了所有选项(包括DIR选项)但失败了。包含这些文件以及 style.css 路径的最佳方法是什么?
解决方案
在 index.php 中:
include (__DIR__.'/include/header.php');
在 header.php 中:
include (__DIR__.'/../config/db.php');
include (__DIR__.'/../assets/css/style.css');
推荐阅读
- python - Issues with PySpark on Jupyter notebook with .show() DataFrame once it is passed through a function
- r - 使用不断变化的列表重命名 R 数据框中的列的函数
- python - InvalidArgumentError: input_1_1:0 is both fed and fetched
- sql-server - 使用 sp_send_dbmail 发送的邮件将嵌入的图像显示为附件
- vba - 公式中的Excel VBA变量
- r - Eigenvalues of a matrix, assuming symmetry
- php - 获取解析错误,PHP代码中的语法错误
- python - 获取列的“循环滞后”
- batch-file - 如何使文本行的第一部分唯一并批量连接第二部分?
- javascript - 我如何操作一个 javaScript 对象