我在這個網站搜索了一個答案,但沒有找到任何。PHP從輸入文件到txt文件
我有一個表單,我想獲取輸入的內容寫入一個txt文件。爲了簡單起見,我寫了一個簡單的表單和一個腳本,但它讓我一直處於空白頁面。下面是我得到
<html>
<head>
<title></title>
</head>
<body>
<form>
<form action="myprocessingscript.php" method="post">
<input name="field1" type="text" />
<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
</form>
<a href='data.txt'>Text file</a>
</body>
,這裏是我的PHP文件
<?php
$txt = "data.txt";
$fh = fopen($txt, 'w+');
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both fields are set
$txt=$_POST['field1'].' - '.$_POST['field2'];
file_put_contents('data.txt',$txt."\n",FILE_APPEND); // log to data.txt
exit();
}
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
?>
不'myprocessingscript.php'產生任何進一步的輸出?如果你的第二個代碼片段是整個PHP腳本,那麼你應該得到一個空白頁面,因爲你沒有生成任何輸出。 – acme 2013-02-21 09:46:28
另外,你得到一個空白頁面是正常的,你不是'echo()'任何東西到客戶端。 – Floby 2013-02-21 10:13:23