简体   繁体   English

如何将textarea数据保存到html文件中?

[英]How to save a textarea data into a html file?

My question in slightly different from the $fopen $fwrite function 我的问题与$ fopen $ fwrite函数略有不同

Since what i would like to achieve is have a button below the textarea name "save as html" 因为我想要实现的是在textarea名称下面有一个按钮“另存为html”

when i press 当我按下

a popup box appear just like window 'save as..' dialog for the user to choose which place they want to store the file 弹出框就像窗口“另存为...”对话框一样,供用户选择要存储文件的位置

when click save, the file is store in that place 单击“保存”时,文件将存储在该位置

How to implement this kind of function? 如何实现这种功能? Thank you. 谢谢。

The best way I could think to do that would be to use server side code. 我能想到的最好方法是使用服务器端代码。 Have the button submit the form to the server, create a temporary HTML file and send it back in the response with the content disposition header like 让按钮将表单提交给服务器,创建一个临时HTML文件并将其发送回响应中,并使用内容处理标题

Content-Disposition: attachment; filename="fname.ext"

The "Open/Save As" dialog is shown by any Web Browser when it receives a file stream in HTTP-Response and the headers of the response also indicate that the content is a File. 任何Web浏览器在HTTP响应中接收文件流时都会显示“打开/另存为”对话框,并且响应的标题也指示内容是文件。

Hence it is not possible to open "Save As" dialog from client side code. 因此,无法从客户端代码打开“另存为”对话框。 You will have to submit the textArea value to the server and then Browser would open the "SaveAs" dialog. 您必须将textArea值提交给服务器,然后Browser将打开“SaveAs”对话框。

If you want to save the server trip, you will have to write JQuery/JavaScript code to let the user save the contents on his disk ie $fOpen and $fWrite. 如果你想保存服务器之旅,你将不得不编写JQuery / JavaScript代码让用户保存他的磁盘上的内容,即$ fOpen和$ fWrite。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM