Use a different H::T to generate CSV type output instead of HTML output. Put the content-type header into the H::T template files instead of your program. Decide which template to use by examining the extension of the CGI (.cgi vs .csv)
Chris -- Chris Davies, Manheim Online Tel. 0113 393-2004 Fax. 0870 444-0482. Mobile 07778 199069 -----Original Message----- From: Martijn van den Burg [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 05, 2002 3:39 PM To: [EMAIL PROTECTED] Subject: [htmltmpl] Downloading data to file. How? Hi, Problem: I want the $USER to have the possibility to download the data that is displayed (using H::T) in his browser to a file in his own directory. Without the fancy HTML formatting. I'm talking about tables with numbers obtained from a MySQL database. Purpose: data download to, eg. M$ Excel, for further manipulation. Precondition: I'd really like to reuse the same datastructures I now send to H::T. Possible solutions: (1) Always save each query output also to file on the webserver (with a unique ID) using a dedicated 'ASCII' template and $template->ouput(print_to => *STDOUT) and then provide the $USER with a d/l link for that unique file. Instead of table formatting I'd use CSV formatting. Pro: relatively easy to do Con: pollution of the webserver: need to remove 'stale' files (2) Don't use H::T and instead make separate subroutines for each dataset. Downloading them to the user with something like this: print $query->header('-type'=>'application/octet-stream'); open (FILE, "<${docdir}/${file_name}") or fatal_error("$!\n"); foreach (@lines_of_formatted_data) { print FILE "$_\n"; } close (FILE); (3) Use a CPAN module someone else wrote but which is as yet unknown to me. Your input is much appreciated. Martijn -- +----------------------------------+ Martijn van den Burg ASML, CS PPC Inform@tion Systems Voice: +31 (0)40 268 3856 +----------------------------------+ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
