xoxox xoxox - 2 months ago 12
HTML Question

Get textbox text

When I click the button the text from the textbox should be written to a

file, which then should be downloaded. Somehow the
function doesn't work, I already tried to link the php file with a
>, but then I can't read the textbox text.

Here's my code:


$text = $_POST['text'];
print ($text);

$filename = 'test.txt';
$string = $text;

$fp = fopen($filename, "w");
fwrite($fp, $string);

header('Content-disposition: attachment; filename=test.txt');
header('Content-type: application/txt');


<title>Text Editor</title>
<textarea name="text" rows="20" cols="100"></textarea>
<button type="submit" value="submit">Download Text</button>


Firstly, you need to have a <form> tag to be able to submit your data:

<form action="add your php filename here" method="post">



You might also need to make your <button type="submit" into <input type="submit"