HTML - .txt的简单输入



我正在尝试弄清楚如何制作一个简单的 html 代码,以便每当页面上的任何人在提供的文本框中键入任何内容并点击提交时,它都会将该书面文本添加到我的服务器上已经存在的.txt文件中。

更新 2/20/14 9:29AM:嗯,这很不幸。我有点想我需要.php但遗憾的是,我的 wepbage 是通过宅基地托管的,它们没有.php功能。只是希望有一个解决方法。感谢您的回复。

如果您的服务器可以运行 php,那么当用户单击提交时,可以请求以下页面。(使用发布方法)

<?php
    $in = $_POST['name'];
    $file = 'names.txt';
    // Open the file to get existing content
    $current = file_get_contents($file);
    // Append a new person to the file
    $current .= $in;
    // Write the contents back to the file
    file_put_contents($file, $current);
?>

你必须使用 PHP 来做到这一点。使表单上的表单操作链接到PHP脚本,并在内部有类似的东西。

<?php
    $file = 'test.txt';
    $currentText = file_get_contents($file);
    $currentText .= $_POST['text'];
    file_put_contents($file, $currentText);
?>

最新更新