1

Using JavaScript I want to:

  1. generate a file locally and serve it to the user as
    Content-Disposition: attachment;

  2. load a file locally from the user via a form <input type="file" />

Is this possible, and if so, what is the most straightforward way to do it?

JL344
  • 131
  • 5
  • Is it the same file? Then upload it directly. – Bergi Aug 01 '12 at 23:52
  • 3
    For the first question: http://stackoverflow.com/questions/609530/download-textarea-contents-as-a-file-using-only-javascript-no-server-side – Thilo Aug 01 '12 at 23:52
  • The way I would do it would be to generate the file with a server-side language (such as PHP), hand it to the user as a download, and then, as you stated, get the file back via file-upload (and then process it in the server). – JCOC611 Aug 01 '12 at 23:52
  • 2
    For the second question: https://developer.mozilla.org/en/DOM/File – Thilo Aug 01 '12 at 23:54
  • @JCOC611: I know it seems easier and more straightforward that way, but the back-and-forth is precisely what I wanted to avoid when I just want to work with the contents of the file locally. – JL344 Aug 02 '12 at 00:24
  • @Thilo: thanks for the suggestions, that ought to give me good start. – JL344 Aug 02 '12 at 00:25
  • @JL344: The reason I suggested that way was because, as far as I know, it's usually easier to work server-side based. However, if you want to work exclusively client-side, then that is much better for the end user. Good luck! – JCOC611 Aug 02 '12 at 00:37
  • @Thilo That question and its answers are horribly outdated. – NullUserException Nov 16 '12 at 22:39

0 Answers0