发送文本到txt文件格式的顶部

时间:2019-02-14 02:03:07

标签: php forms post

我在堆栈中找到了一个很好的工作代码,该代码几乎可以完全实现我想要的功能,但是没有在文本文件的顶部发布新消息,而是将其放在末尾。

是否有可能,在这种情况下如何实现,以至于它在顶部添加了新的输入?

<form action="send.php" method="post">
    Line:<br><input type="text" name="line" size="3"><br>
    Message:<br><input type="text" name="msg" size="35"><br>
    <input type="submit" value="Send">
</form>

<?php
$path = 'info.txt';
if (isset($_POST['line']) && isset($_POST['msg'])) {
$fh = fopen($path,"a+");
$string = $_POST['line'].' - '.$_POST['msg'].' <br> ';
fwrite($fh,$string);
fclose($fh);
} ?>

0 个答案:

没有答案