使用输入用 PHP 编辑 Txt 文件?

Editing a Txt File with PHP using inputs?

提问人: 提问时间:9/5/2020 更新时间:9/5/2020 访问量:40

问:

我想编写一个可以在服务器上编辑简单文本文件的 Web 应用程序。用户将字符串写入表单,然后按输入(按钮)。该文件应该已更改,但它不起作用。

我的HTML;

<form name="form" action="" method="post">`
<input type="text" id="msg" name="msg" placeholder="Enter message...">
</form>
<input type="submit" name="send" value="Send">

我的PHP:

<?php
if(isset($_POST['send'])){
 $chatfile = fopen("chat.txt", "w");
$message = $_POST['msg'];
fwrite($chatfile, $message);
fclose($chatfile);
}
?>

这一切都在一个文件中。

php html 文件 按钮

评论

5赞 brombeer 9/5/2020
放置在表单中(或使用指向要关联的表单属性的属性)<input type="submit" name="send" value="Send">formid
0赞 M. Eriksson 9/5/2020
建议:只需一行即可将数据保存在文件中:file_put_contents('chart.txt', $_POST['msg']);

答: 暂无答案