Reputation: 4427
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
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
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