首页 > 解决方案 > 在 .ini 文件中使用相对路径

问题描述

我在我的网站https://www.example.com的根目录中创建了一个 .user.ini,只有一行:

auto_prepend_file = "/path/to/my/website/includes/prepend.php"

它工作正常。

我现在在 https:// development .example.com 设置开发环境 我将所有文件从生产站点复制到开发站点。

有没有办法重写我的 .user.ini 以使用相对路径?像这样的东西:

auto_prepend_file = doc_root + "/includes/prepend.php"

或者可能

auto_prepend_file = "includes/prepend.php"

这样我就不必在每次进行生产或开发工作时都更新 .user.ini 文件。

谢谢。

标签: phppathini

解决方案


只需将相对路径保留在 ini 文件中,稍后在 php 逻辑中的“自动前置”过程中添加 doc-root。

您可以通过 index.php 在 index.php 中获取文档根目录

define('DOCUMENT_ROOT', __DIR__);

并在您喜欢的脚本中随处使用它。


推荐阅读