0
如何保存多个数据字符串而不删除旧的(在同一个文件中)?如何保存多个数据字符串而不删除旧的(在同一个文件中)?
我使用POST从形式到TXT文件添加数据,但它一直覆盖旧数据:
$txt = "joined_teams.txt";
$fh = fopen($txt, 'w+');
if (isset($_POST['teamname']) && isset($_POST['shortname']) && isset($_POST['1steamid']) && isset($_POST['2steamid']) && isset($_POST['3steamid']) && isset($_POST['4steamid']) && isset($_POST['5steamid'])){ // check if both fields are set
$txt=$_POST['teamname'].' - '.$_POST['shortname'].' - '.$_POST['1steamid'].' - '.$_POST['2steamid'].' - '.$_POST['3steamid'].' - '.$_POST['4steamid'].' - '.$_POST['5steamid'];
file_put_contents('joined_teams.txt',$txt."\n",FILE_APPEND); // log to joined_teams.txt
exit(header('location:http://coprogames.com'));
}
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file