Welcome Guest, Not a member yet? Register   Sign In
[Solved] Write File Not Working
#1

[eluser]riwakawd[/eluser]
Got problem with the write_file function for my APPPATH to database.php file will not write_file.

But will write_file if is out side of directory. I am pretty much stuck on this, is very strange not working.

Code:
if ($this->form_validation->run() == false) {

   $this->load->view('template/step_3', $data);

   } else {

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

      // Does Not Write to File
     write_file(APPPATH . 'config/database.php', $get_template_file_contents, 'r+');

     // Writes to files OK
     write_file(dirname(FCPATH) . '/admin/application/config/database.php',
$get_template_file_contents, 'r+');

     write_file(dirname(FCPATH) . '/catalog/config/database.php', $get_template_file_contents, 'r+');

     $this->load->library('migration');
     $this->migration->version(1);
     redirect('step_5');
      
     } else {
         redirect('step_3');
     }
}
#2

[eluser]riwakawd[/eluser]
After working it out for couple hours have now got all working.

Code:
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', $data, true);
        write_file(dirname(FCPATH) . '/admin/application/config/database.php', $get_template_file_contents, 'r+');
        write_file(dirname(FCPATH) . '/catalog/config/database.php', $get_template_file_contents, 'r+');
        write_file(FCPATH . '/application/config/database.php', $get_template_file_contents, 'r+');
   }

   if(write_file(FCPATH . '/application/config/database.php', $get_template_file_contents, 'r+') == true) {

    $this->load->library('migration');
        $this->migration->version(1);
     redirect('step_5');

   } else {
    redirect('step_3');
   }




Theme © iAndrew 2016 - Forum software by © MyBB