0

我需要将一些数据从 HTML 表单写入data.txt文件(txt 文件有 777 权限)

我使用的 HTML 是index.html

<form action="index.php" method="POST">
<input name="field1" type="text" />
<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">

PHP 文件是index.php

<?php
$txt = "data.txt"; 
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both fields are set
    $fh = fopen($txt, 'a'); 
    $txt=$_POST['field1'].' - '.$_POST['field2']; 
    fwrite($fh,$txt); // Write information to the file
    fclose($fh); // Close the file
}
?>

但是当我使用表单保存数据时,它会显示一个消息框来下载index.php

我做错了什么?

4

0 回答 0