テキスト領域にテキストを入力し、送信時にphpがテキスト領域に入力されたテキストを含むはずのテキストファイルを生成するこのフォームがあります。しかし、問題は私が書いたコードにあります。テキストファイルはダウンロードされますが、テキストが含まれていません。したがって、テキスト領域をテキストタイプの入力フィールドに変更すると、テキストファイルのデータが返されますが、改行はありません。これが私のコードです
<html><body>
<form action="download.php" method="post">
<textarea id="output" name="output"></textarea>
<input type="hidden" name="op" type="hidden" id="fakeop" >
<input type="submit">
</body></html>
そしてphpファイルの内容は
<?php
$filename = 'random.txt';
$somecontent = $_REQUEST["output"];
!$handle = fopen($filename, 'w+');
fwrite($handle, $somecontent);
fclose($handle);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: ". filesize("$filename").";");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
readfile($filename);
?>
$ somecontent = $_REQUEST["op"]に変更した場合; 内容を含むテキストファイルを返します。しかし、なぜその出力がないのですか?