doulun7739 2013-01-31 10:51
浏览 19

在dir结构中搜索app配置文件是一个坏主意吗?

I have a php app with a configuration file in its root. If I include it by it's absolute path, then I get a problem when I move the app elsewhere. If I include it by relative path, I get a problem when I move the file where the config is included. So, I've come up with something like this to search for the app config file down the directory structure.

$relative_path = "";
for ($i=0; $i<6; $i++) {
    if (file_exists($relative_path."config.php")) {
        require ($relative_path."config.php");
        break;
    } 
    $relative_path .= "../";
}

Could this be a bad idea?

  • 写回答

3条回答 默认 最新

  • dq_609586475 2013-01-31 10:54
    关注

    Personally i use dirname(__FILE__) . '/path/to/config.php';

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题