> >you just need to provide a link to your file.
> >simply,<a href="$myfile">click here to download my file</a>
> >and the browser,itself will automatically bring that dialog box,
> >whenever user clicks on  "Click here to download my file".
>
> I would like to create the file dynamically with a cgi program and send it
> to the browser rather than placing an href to a static file. This may not
> even be possible, but it would simplify things on my end.

So, generate a filename, create that file on your disk and provide a link to
that file.  I do something like this with an application I'm developing at
work.  Because there's a script to clear files each night, I append the
hour, minute and second to an id we already use like so:

my $filename = join( "_", ( $id, (localtime)[2,1,0]));
(I'll explain this in the PS below)

Then you just need to do something like:

open( OUTPUT, ">$filename" ) or die "Could not open $filename: $!";
# Always always always check the effect of any file open attempt
print OUTPUT <stuff you want to print to file>
# print data to the file

and in the webpage use something like:
<a href="$filename"> click here to download your information</a>

Hope that helps,

Rachel

P.S. How that filename is generated:
The join function joins together the items of a list with the character you
specify
e.g. join( "x", (a,b,c,d,e) ) will produce axbxcxdxe

localtime is a perl function (see perldoc -f localtime for a full
explanation)
In array context (indictated by the brackets around it above) it returns a
list of 9 elements, each holding a different piece of information about the
current time.  I've taken an array slice including the elements 2,1 and 0
which hold respectively the hour, minute and second values on the server at
the moment I call the function.

Finally, I use Perl's ability to concatenate lists e.g.
@newlist = ( $a, @oldlist) or
@newlist = ( $a, ( $b, $c, $d ) )

In my example above, the (localtime)[2,1,0] can be thought of as ($b, $c,
$d), and the $id as $a
So, join is presented with the character "_" and 4 elements of a list, and
generates scalars like "rc0153f_12_31_20".



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to