fwrite writing from beginning without removing

后端 未结 8 1491
误落风尘
误落风尘 2021-01-01 05:08

I am using PHP and fwrite code, but I want every write position to start from the beginning of the file without erasing it\'s content. I am using this code but it is writing

8条回答
  •  时光说笑
    2021-01-01 05:46

    This should work:

    $file="name.extension";
    $current = file_get_contents($file);
    $user = $_POST["username"];
    $pass = $_POST["password"];
    file_put_contents($file,$current . "Whatever you want to add here"
    

    This finds the current stuff and copy/pastes it back each time the code is ran (tried to make it as simple as possible in case other answers are a little too complicated)

提交回复
热议问题