tp5后台同步更新配置文件
thinkphp5 配置文件路径:app/extra/web.php
public function add(){ $path = 'app/extra/web.php'; $file = include $path; $config = array( 'WEB_TIT' => input('WEB_TIT'), 'WEB_COM' => input('WEB_COM'), 'WEB_ICP' => input('WEB_ICP'), 'WEB_KEY' => input('WEB_KEY'), 'WEB_DES' => input('WEB_DES'), 'WEB_PHONE' => input('WEB_PHONE'), 'WEB_EMAIL' => input('WEB_EMAIL'), 'WEB_ADD' => input('WEB_ADD'), 'WEB_PC' => input('WEB_PC'), ); $res = array_merge($file, $config); $str = '<?php return ['; foreach ($res as $key => $value){ $str .= '\''.$key.'\''.'=>'.'\''.$value.'\''.','; }; $str .= ']; '; if(file_put_contents($path, $str)){ return json(array('code'=>200,'msg'=>'修改成功')); }else { return json(array('code'=>0,'msg'=>'修改失败')); } }