OT perl question

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Victor Odhner
Date:  
Subject: OT perl question
Hi, Charlie.

> would it be possible to take the text, convert
> it to a .txt file and put a link on the created
> page to allow for the download of the file.


You don't need to write a permanent file,
and don't want to since you have no way of
knowing how long to retain that temporarily
permanent file. The formula I'm showing here
will just make the text appear in the user's
browser as a .txt file, and then they can do
a "Save as..." to write it to disk.

Someone handed this incantation to me as I'm
handing it to you. This is cookbook voodoo
stuff and I can't explain what everything means;
but it worked great for me. You may try
omitting parts of the formula to see what
the effects are.

1. First, I'm assuming that you have presented
the user with a query form of some sort, and the
user has filled in the form's variables to be
processed by your CGI. In the "action" for the
form, make up a URL that includes "path-info"
ending in .txt so that the browser thinks it's
asking for a text file.

Example:
action="http://foo.com/cgi-bin/myprog.cgi/sqlout.txt"

The path-info may be followed by some GET parameters
here, but I'm guessing you will be using POST with
form parameters instead, such as text fields and
checkboxes.

The CGI can test the path-info which would be
"sqlout.txt", or maybe it doesn't even need to
look at this. The point is that the URL ends
with ".txt" to put the browser in the right
frame of mind.

2. Now, when myprog.cgi spits out the result to
 STDOUT, it needs a header like the following.
 I don't know what the ETag is, but its argument
 in our case was a unique identifier for the
 information we were spitting out:
   print( "Content-Type: text/plain\n",
          'ETag: "', $unique_id, '"', "\n\n" );
 ... note the empty line following these two
 lines.


So, STDOUT contains this:
---------------------------
Content-Type: text/plain
ETag: 'foo098234'
<a null line>
<plain text>
---------------------------

That oughta do it. Good luck.

Vic
http://members.cox.net/vodhner/