Using php, how to insert text without overwriting to the beginning of a text file

前端 未结 4 1489
灰色年华
灰色年华 2020-12-06 03:05

I have:

 \"\")
{
   fwrite($file,         


        
4条回答
  •  Happy的楠姐
    2020-12-06 03:21

    If you want to put your text at the beginning of the file, you'd have to read the file contents first like:

     "")
    {    
        $existingText = file_get_contents($file);
        fwrite($file, $existingText . $_POST["lastname"]."\n");
    }
    
    fclose($file);
    
    ?>
    

提交回复
热议问题