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';

    评论

报告相同问题?

悬赏问题

  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播