0

I I've created a very simple web based text editor- http://bit.ly/XNFrE4

But one of the biggest lack of this app is that there is no way to save it as text file(.txt).

So I'm looking for an idea on how to make it possible to save the content as .txt file.

Thanks.

Will Hawker
  • 733
  • 3
  • 14
john
  • 87
  • 3
  • 8
  • 1
    You'll have to send the content server side to save it to a file. This cannot be done with JavaScript locally as JavaScript cannot access the file system. – War10ck Feb 06 '13 at 13:38
  • Consider changing your question title - it doesn't say anything about the subject of your post – Marek Feb 06 '13 at 13:49

3 Answers3

4

Put your file into URI string (encode with base64) and open it as a new link.

BTW. there are some other, more complicated solutions: http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side

Ivan Kuckir
  • 2,327
  • 3
  • 27
  • 46
0

One way would be to:

  1. Submit a form and send the input as parameter to something like "saveFile.php"
  2. In "saveFile.php" send the submitted file as download (*.txt) back to the user.
Adrian
  • 2,233
  • 1
  • 22
  • 33
-1

I like how clean it is! I'd suggest to set a max width of around 6-700 pixels for the contenteditable div, this will give a better readability. It would be able if you could use titles and lists and other html elements in the text.

Saving the document could be done by sending the content to the server with an ajax request and then create a txt file on the server and send it back to the user

http://www.tizag.com/phpT/filecreate.php

I suggest you use the current time to create the file to avoid file-swap when two people save in a small time lapse.

$ourFileName = "simple-editor-".time().".txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
$myFile = $ourFileName;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);

fclose($fh);

If you're really into trying some backend codes i'd love if there was authentication and the possibility to save files on the server.

I think you can create a txt file with js as well, but I would go with php

Jonas Grumann
  • 10,438
  • 2
  • 22
  • 40