Leo Chan
Leo Chan

Reputation: 4427

How to save a textarea data into a html file?

My question in slightly different from the $fopen $fwrite function

Since what i would like to achieve is have a button below the textarea name "save as 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.

Upvotes: 0

Views: 1045

Answers (2)

Ameya
Ameya

Reputation: 627

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.

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.

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 i.e. $fOpen and $fWrite.

Upvotes: 1

James Hay
James Hay

Reputation: 7325

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

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

Upvotes: 1

Related Questions