dongtong7990 2013-08-07 15:21
浏览 47
已采纳

Codeigniter配置文件在运行时更改

Is possible to edit config file at runtime? I'm developing a module manager and this has to be able to change some aspects of the configuration dynamically.

This means being able to read and this writte this file at runtime, and modify for example this line.

$config ['WebTitle'] = 'foo';

Some tips?

PD: I dont wont to create a new table in database to store this configuration. Alternatives?

EDIT: After searching for some time I found an answer quite similar to what I'm looking for, but have not had success.

It might. Htaccess block this?

Link to response : link

  • 写回答

2条回答 默认 最新

  • duanbo7517 2013-08-07 18:22
    关注

    It sounds like you want to actually modify the config file. If so, yes, you can do it. You will need to make sure the file is writable by the web server. Then just fopen() the file, fread() it into memory, change what's needed, then fwrite() it back out again. Easy! :)

    Please keep in mind there is a security risk if you are in a shared hosting situation.

    If you are doing a setup process, you may want to check permissions with a call to fileperms(). Then if the permissions are not correct, tell the user they will need to ftp into their account and make the file writable. Then, after setup is done, tell the user to mark the file as non-writable again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用