多个@fopen不工作CI


Multiple @fopen Not Working CI

我在codeigniter模型中有一个函数,它获得数据库的模板,因此当我填写表单并单击提交按钮时,它将保存将输入写入codeigniter中的database.php文件。

我有麻烦让两个@fopen工作。当我再添加一个位置时,a会清除我试图写入的文件中的所有数据。

public function load_app_ins() {
$template = file_get_contents(APPPATH . 'modules/install/config/database.php');
$replace = array(
'HOSTNAME' => $this->input->post('hostname'),
'USERNAME' => $this->input->post('username'),
'PASSWORD' => $this->input->post('password'),
'DATABASE' => $this->input->post('database'),
'DBDRIVER' => $this->input->post('dbdriver'),
'DBPREFIX' => $this->input->post('dbprefix')
);    
$template = str_replace(array_keys($replace), $replace, $template);
// Trying To Get Main Directory APPLICATION Not Load Clears Data Should Load 
$file = @fopen(dirname(FCPATH) . '/application/config/database.php', 'w+'); 
// This Location Works OK From Install Directory
$file = @fopen(APPPATH . 'config/database.php', 'w+');
if ($file !== false) {           
$response = @fwrite($file, $template);
fclose($file);
if ($response) {
return true;
} else {
echo 'Error when process'; die;
}
}

我阅读了更多关于codeigniter用户指南的内容,发现那里更容易。Write_file现在好多了

unset($this->db);
$dsn = $this->input->post('db_driver').$this->input->post('db_username').':'. $this->input->post('db_password').'@'.$this->input->post('db_hostname').'/'.$this->input->post('db_database');
if (is_resource($this->db->conn_id) OR is_object($this->db->conn_id)) {
$data = array();
$data['db_hostname']    = $this->input->post('db_hostname');
$data['db_username']    = $this->input->post('db_username');
$data['db_password']    = $this->input->post('db_password');
$data['db_database']    = $this->input->post('db_database');
$data['db_driver']  = $this->input->post('db_driver');
$data['db_prefix']  = $this->input->post('db_prefix');
$get_template_file_contents  = $this->load->view('template/configuration/database.php', $data, true);
write_file(APPPATH . 'config/database.php', $get_template_file_contents, 'r+');
write_file(dirname(FCPATH) . '/admin/application/config/database.php', $get_template_file_contents, 'r+');
write_file(dirname(FCPATH) . '/catalog/application/config/database.php', $get_template_file_contents, 'r+');
redirect('setup/step_4');
}