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