当我单击该按钮时,文本框中的文本应该写入.txt
文件,然后应该下载该文件。不知怎的,isset
功能不起作用,我已经尝试链接php文件与<form
>,但我不能阅读文本框文本。获取文本框文本
这里是我的代码:
<?PHP
if(isset($_POST['submit']))
{
$text = $_POST['text'];
print ($text);
$filename = 'test.txt';
$string = $text;
$fp = fopen($filename, "w");
fwrite($fp, $string);
fclose($fp);
header('Content-disposition: attachment; filename=test.txt');
header('Content-type: application/txt');
readfile('test.txt');
}
?>
<html>
<head>
<title>Text Editor</title>
</head>
<body>
<textarea name="text" rows="20" cols="100"></textarea>
<p>
<button type="submit" value="submit">Download Text</button>
</body>
</html>
+1就是这样! :) – Havelock
谢谢!我之前已经尝试过