如何将textarea的内容保存为PHP或JS中的html文件

时间:2015-02-14 13:09:08

标签: javascript php html

所以基本上我有一个textarea和一个使用form方法保存为按钮。当用户单击另存为时,将弹出一个对话框,询问文件名是什么以及保存位置。这可能使用php或javascript吗?

1 个答案:

答案 0 :(得分:0)

你可以用php做到这一点。只需按照以下步骤操作

1->接受来自用户的输入(文件名和文字)
2->清理输入

然后这个代码片段适用于你

<?php
$file = $_POST['filename']. ".txt"; // getting filename and storing to variable

$content = $_POST['text_from_user']; // getting file contents from textarea

// Write the contents to the file
file_put_contents($file, $content);
?>