나는이 사이트에서 답변을 검색했지만 couldnt를 찾았습니다.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>
있어 무엇이며, 여기에 데이터가 GET
방법에가는 것을, 내 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
또한 공백 페이지를 얻는 것은 정상적인 현상이며, 클라이언트에게는 아무 것도'echo() '하지 않습니다. – Floby