[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

option to save to file vs display on browser?

I currently get stdout from a C program and print results to the browser (see attached code snippet).  I now give the user the option to press a different button if they want to write the output to a file.  How can I make (at least in Netscape) the file->save as dialog box come up, then have the output written to the selected file on their PC?  

Thanks! - BB

if ($option eq "Save as file") {
     ???
}
else {   #show to browser
 print "<CENTER><TABLE BORDER=0><TR>\n";
    while (<PLPRICE>) {
        ($col1, $col2, $col3, $col4) = split(/;/, $_, 4);
        print "</TR><TR>\n";
        if ($col2 eq "Quantity") {
            print "<TH>", $col1, "</TH>\n";
            print "<TH>", $col2, "</TH>\n";
            print "<TH>", $col3, "</TH>\n";
            print "<TH>", $col4, "</TH>\n";
        }
        elsif ($col3 eq "") {
            print "<TH ALIGN=LEFT>", $col1, "</TH>\n";
            print "<TD COLSPAN=3>", $col2, "</TD>\n";
        }
        else {
            print "<TH ALIGN=LEFT>", $col1, "</TH>\n";
            print "<TD>", $col2, "</TD>\n";
            print "<TD>", $col3, "</TD>\n";
            print "<TD>", $col4, "</TD>\n";
        }
    }
    print "</TR></TABLE></CENTER>\n";
    close PLPRICE;
}
0
borghard
Asked:
borghard
  • 2
  • 2
1 Solution
 
bigbedCommented:
If you send an unrecognized content-type to the browser, it should prompt it to give the save-as box.
Normally a CGI will send:
Content-Type: text/html
for an HTML page.
In this case you could send:
Content-Type: application/octet-stream
and it should get the save-as box shown.
0
 
borghardAuthor Commented:
I had tried that and it didn't seem to work.  I now realize my (silly) mistake.  I had a left a debug print statement in just before this.  Once  comment that out, it works beautifully.  If you want to lock this question, I'd like to give you 60 points anyways.
Thanks!
0
 
bigbedCommented:
Thanks!
If you send an unrecognized content-type to the browser, it should prompt it to give the save-as box.
Normally a CGI will send:
Content-Type: text/html
for an HTML page.
In this case you could send:
Content-Type: application/octet-stream
and it should get the save-as box shown.
0
 
borghardAuthor Commented:
thanks again - BB
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now