chimni has asked for the wisdom of the Perl Monks concerning the following question:


Hi monks, I have a cgi form that takes user input ,queries a database on the given parameters and generates a table.
I would like to give an option of saving this table as a CSV file.
I can convert the table to csv.my problem is i cannot figure out how to deal with the fact that the web page can be accessed from anywhere and i have to give an option for the user to save the table to a csv file on his disk.
(only thing i can think of is to take email address as an input and mail him the file).i am sure there is a better way.
Any suggestions?
Regards,
chimni
UPDATE:Matija: Yes, upon clicking a button i want the data in the table to be saved as a csv file.
So your saying i should make a sub-routine,call it on click,write the headers your provided [Content-type=application/octet-stream; filename="some_filename"],convert my html to csv and output it

Replies are listed 'Best First'.
Re: Save HTML table as CSV on local disk
by matija (Priest) on Mar 22, 2004 at 13:28 UTC
    You want to trigger the browser's "Save as file" action, is that it?

    In that case, instead of ouputing Content-type: text/plain or whatever you usualy output, try

    Content-type=application/octet-stream; filename="some_filename"
    Since people usualy don't have an application bound to octet-stream, most browsers should just save it.

Re: Save HTML table as CSV
by pelagic (Priest) on Mar 22, 2004 at 13:22 UTC
    Set mime type of your output using
    my $in = new CGI; print $in->header('text/comma-separated-values');
    and your user should automatically be prompted for an appropriate action (e.g. save file ...)
    pelagic

    -------------------------------------
    I can resist anything but temptation.