I have issue saving textarea to file. I used POST method to send the form to the other page then, in the next page I can't include the textarea content with the file Im not sure what is the problem.
Is there any idea about what is the problem?
Here are the two pages:
page1:
<!DOCTYPE HTML>
<html>
<head>
<title>Save</title>
</head>
<body>
<form action="page2.php" method="post">
<span>name:</span>
<input type="text" name="name"><br>
<span>file extension: </span>
<select name="ext" id="ext">
<option value=".txt">.txt</option>
<option value=".doc">.doc</option>
</select>
<textarea name="txt1" id="txt1" cols="15" rows="10"></textarea>
<br>
<input type="submit" name="submit" id="submit" value="Save">
</form>
<br>
</body>
</html>
-page2.php
$txt1 = $_POST['txt1']; //textarea
$name = $_POST['name'];
$ext = $_POST['ext']; //choose from multiple extensions
if ($ext == '.txt') // In case if I want to add more than extension.
{
$file = "'. $name$ext.'" ;
$output = "$txt1";
file_put_contents($file, $output);
$text = file_get_contents($file);
header("Content-Description: File Transfer");
header("Content-Type: application/text/plain");
header("Content-Disposition: attachment; filename=".basename($file));
ob_clean();
flush();
readfile($file);
exit;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…