上传论坛结果到文件


Upload forum results to file

<form method="post">
  Username: <input name="username" type="text" /><br />
  Password: <input name="password" type="text" /><br />
  Email: <input name="email" type="text" /><br />
  Subject: <input name="subject" type="text" /><br />
  <input type="submit" value="Submit" />
  </form>

当有人填写了上面的表单,结果是否可能被上传到一个文本文件,比如results.txt,而不是通过电子邮件发送?

因此,例如,如果网站链接是hithere.com,结果将被上传到一个密码保护的文本文件hithere.com/results.txt。

谢谢!

这是一个可能从你的。php表单处理程序文件执行的代码

<?php
  $myfile = fopen("result.txt", "a") or die("Unable to open file!");
  $text = $_POST['username']."'n";
  $text .= $_POST['password']."'n";
  $text .= $_POST['email']."'n";
  $text .= $_POST['subject']."'n'n";
  fwrite($myfile, $text);
  fclose($myfile);
?>

另外,您可能需要添加一个action属性到您的表单标签,其值应该是相同的。php文件名(或路由,如果它不在同一文件夹)。例如,如果你的php文件是form_handler.php你应该有<form method='post' action='form_handler.php'>

对上面的php代码进行一点解释,您使用第二个参数"a"打开文件,以告诉服务器您不想覆盖文件的内容,而只是在现有内容之后添加一些内容(追加)。如果你想覆盖的内容,参数应该是"w",然后你设置所有的文本在一个变量,并写在文件与fwrite()。之后,您需要使用fclose()

关闭该文件。

编辑:如果你不知道,"'n"是换行符。