4

I have one page that shows links, and I have some text data. How can I make using C++ CGI that by clicking on hyperlink "Save As" dialog will appear and certain amount of my text will be saved with user-defined path and name to the file on the users filesystem.

Actually, main question is how to show "Save as" dialog. After it, I think, everything will be easy.

HelloHi
  • 165
  • 2
  • 10

2 Answers2

2

Just set an appropriate content-type header and then output the file.

The browser takes care of the rest. Any file type it doesn't recognize causes the Save as dialog to be displayed.

jalf
  • 243,077
  • 51
  • 345
  • 550
  • And can you tell me what is optimal size of blocks to split file into, 'cos it can be too large to send it at once? I tried to google something like "optimal html block size" but yet didn't find the answer – HelloHi Dec 06 '12 at 13:18
  • Why do you assume that there is a single size that is *always* optimal? :) And you should probably replace html with http in your google query ;) – jalf Dec 06 '12 at 13:38
  • not, I don't assume that there is silver bullet =) But I have to choose some block size, and I want it to be not just magic number(first my idea war 2014 bytes), but I can't find any info to base on :( "http block size" on google also didn't help. – HelloHi Dec 06 '12 at 13:55
  • Well, I have no clue. But you can send much bigger chunks than that easily – jalf Dec 06 '12 at 14:26
2

They key to forcing the "Save as" dialog with a MIME type the browser can display is the Content-Disposition header.

justinas
  • 6,287
  • 3
  • 26
  • 36
  • And can you tell me what is optimal size of blocks to split file into, 'cos it can be too large to send it at once? I tried to google something like "optimal html block size" but yet didn't find the answer – HelloHi Dec 06 '12 at 13:18