user3565425
user3565425

Reputation: 41

Write to file but not erase

I have a function to write to a .txt file. my problem is that it writes only on the first line, so erases the old line for the new line. I want to append the new lines to the file.

    function logit($log,$filename = ''){
        $logfile = "log/".date('Ymd').$filename.".txt";
        if ($fh = fopen($logfile, 'w')) {
            fwrite($fh, date('H:i:s')." | ".$log."\n");
            fclose($fh);
            return 1;   
        } else
            return false;
     }

Upvotes: 0

Views: 91

Answers (1)

stackrocha
stackrocha

Reputation: 405

You need to search before post your question.. there's many documentation and answers for that problem.. anyway, replace this fopen($logfile, 'w') with fopen($logfile, 'a')

Upvotes: 3

Related Questions