0

So I have an 'export' application that arrives the user at an end page with a textarea with lots of text. Now the workflow is to copy and paste that text from the textarea into a file.

The exported code is getting larger, and we want to encourage users to do this more often, so the copy/paste route is no longer desirable. (Not to mention that my xterm->ssh->screen->vi chain doesn't paste 250K characters so well)

So the problem is this: I have a textarea that has exported code in it, and I want to provide a button that is 'Download this Code to a file'

I'm fairly sure that I will have to hit the server again, but I just want to check all my bases. The ways I can think of doing this (sending generated textarea value as a file ot the browser)

  • Create a script that receives said text as a POST and sends it back with the right Content Headers. This is no desirable because we would be POSTing 250k, which would be slower than:

  • Create a script that regenerates the text area and provide a button the original page that hits the scripts and downloads the file. This is the option I am leaning towards

  • Use Javascript somehow and perhaps beable to skip the server all together and just send the $('.exported').val() to the browser with the right headers? Not sure how to do this atm.

So if anyone has suggestions that'd be great, maybe I'm overlooking something. Thanks!

edit: Download textarea contents as a file using only Javascript (no server-side)

This question says the JS route is not possible (probable)

Community
  • 1
  • 1
jon skulski
  • 2,305
  • 3
  • 18
  • 27
  • exactly, with Javascript only its not posible – acromm May 28 '09 at 18:11
  • the question is: the text its in the server/db or in the client only¡? i dont know but maybe the application consist in a user that generates that TEXT in the client only. evacuate that dude please. – acromm May 28 '09 at 20:05
  • The text is generated on the serverside and sent as a html form element to the client. – jon skulski May 28 '09 at 20:09

4 Answers4

1

I would suggest the following: make your button replace the whole DOM of the page with your text. After that, user will be able to simply press Ctrl+S or ⌘S. Not exactly what you want, but still a shortcut.

I guess you can do it with the following (jQuery):

$ (document.body).html ($ ('#textarea-id').html)

(Not tested)

Alexander Yancharuk
  • 13,817
  • 5
  • 55
  • 55
Ilya Birman
  • 9,834
  • 4
  • 27
  • 31
  • Appreciate the suggestion, though since this is going to be in OSS-space, I'd like to do it right and not muss up the UE. Thanks! – jon skulski May 28 '09 at 20:10
1

I would go with option 2. Simplest and fastest. The other ones are a bit contrived.

If you go with option 2, why even leave the textarea at all?

Martijn Heemels
  • 3,529
  • 5
  • 37
  • 38
  • sweet, sweet validation. Thanks. We're going ot keep the text area because it still might be the case that someone wants to paste part of it. Though it might go away in the future. – jon skulski May 28 '09 at 19:06
0

Following your second option, you could trigger your script with a keyword to send the data as attachment.

Here’s an example of how it could look like:

if (isset($_GET['download'])) {
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;filename="dump.data"');
    echo $data;
    exit;
} else {
    echo '<textarea>', htmlspecialchars($data), '</textarea>';
}
Gumbo
  • 643,351
  • 109
  • 780
  • 844
0

options:

  • TEXT ALREDY IN THE SERVER:

    • MAKE A GETFILE.PHP that reponse that text in a file.
  • TEXT IN THE CLIENT

    • POST THE TEXT TO A GETFILE.PHP and response the file.
    • POST THE TEXT TO A GETFILE.PHP, storage the file and provide a LINK to DOWNLOAD (then you could delete or not the file, depending of your needs)

Here is some example of this http://www.osix.net/modules/article/?id=773

acromm
  • 880
  • 13
  • 24