I'm seeing that this code first creates the file, closes it, then opens it with 'a'
, writes to it, then closes it. Is there a way to simplify it. The idea is that if the file name exists, it needs to be overwritten. I also don't understand the point of unset
. Is it necessary?
$fp = fopen($file_name, 'w');
fclose($fp);
unset($fp);
$fp = fopen($file_name, 'a');
fputs($fp, "sometext");
fclose($fp);
unset($fp);