如何将文本区域的内容保存到PHP或JS中的html文件中


How to save the content of a textarea into a html file in PHP or JS

所以基本上我有一个文本区域和一个使用表单方法的另存为按钮。当用户点击另存为时,会弹出一个对话框,询问文件名是什么以及保存在哪里。这可能使用php或javascript吗?

您可以使用php来完成此操作。只需按照以下步骤

1->接受用户输入(文件名和文本)
2->消毒输入

那么这个片段将适用于u

<?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);
?>