Welcome Guest, Not a member yet? Register   Sign In
How can I write file without overwrite
#1

I'm trying to store my settings, but I can't well. I have too much variable.I have settings[variable] input I use this at form inputs.
Like this;

Form1 has these inputs
PHP Code:
<input type="text" class="form-control" name="settings[facebook]">
<
input type="text" class="form-control" name="settings[twitter]">
<
input type="text" class="form-control" name="settings[site_title]">
<
input type="text" class="form-control" name="settings[site_description]">
<
input type="text" class="form-control" name="settings[site_keywords]"

Form2 has these inputs
PHP Code:
<input type="text" class="form-control" name="settings[jumboH1]">
<
input type="text" class="form-control" name="settings[jumboParagraph]">
<
input type="text" class="form-control" name="settings[panel1]">
<
input type="text" class="form-control" name="settings[panel2]">
<
input type="text" class="form-control" name="settings[panel3]"


And i post these with a hidden input at this controller. It is a method:
This method apply settings.php incoming settings[] array but removing all of settings.php and write again.
PHP Code:
public function applysetting()
 
   {
 
       $submit $this->input->post('submit');
 
       if (isset($submit)) {
 
           $html '<?php' PHP_EOL PHP_EOL;
 
           foreach ($this->input->post('settings') as $key => $value) {
 
               $html .= '$settings["' $key '"]="' $value '";' PHP_EOL;
 
           }
 
           file_put_contents(FCPATH '/settings.php'$html);
 
       }
 
   

If i replace file_put_contents to write_file(FCPATH . '/settings.php', $html, 'a') it rewrites the same things. For example

PHP Code:
<?php

$settings
["jumboH1"]="Login h1 test";
$settings["jumboParag"]="Login paragraph test";
$settings["panel1"]="Panel 1";
$settings["panel2"]="Panel 2";
$settings["panel3"]="Panel 3";
<?
php

$settings
["jumboH1"]="input1";
$settings["jumboParag"]="input2";
$settings["panel1"]="input3";
$settings["panel2"]="input4";
$settings["panel3"]="input5";

<?
php

[size=small][font=MonacoConsolasCouriermonospace]$settings["jumboH1"]="input test";[/font][/size]
[
size=small][font=MonacoConsolasCouriermonospace]$settings["jumboParag"]="input test2";[/font][/size]
[
size=small][font=MonacoConsolasCouriermonospace]$settings["panel1"]="input333";[/font][/size]
[
size=small][font=MonacoConsolasCouriermonospace]$settings["panel2"]="input444";[/font][/size]
$settings["panel3"]="input115"
How can i fix it?
Reply


Messages In This Thread
How can I write file without overwrite - by bomi - 06-17-2019, 01:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB