Output data to a local client directory

Posted on 2003-03-14
Medium Priority
Last Modified: 2013-12-25
I've recently 'inherited' a web app written in CGI, which queries a database and displays the results on a browser page.

I need to add some functionality to allow the user to download the results of the query to their local drive. I'm not sure what format this file should be at the moment.....Excel would be perfect, but I'd settle for a csv file if that is easier.

How do I go about doing this?

Ideally I'd like to prompt the user to select a file location using a common dialog, and then have the query results saved to the appropriate file format in the appropriate location.

Question by:mrt1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 48

Accepted Solution

Tintin earned 500 total points
ID: 8139739
Just output an appropriate MIME type, eg:

Content-Type:  application/ms-excel

You didn't say what language the app is written in, so I'll leave it to you to add the appropriate print (or equivalent) statement.

Assisted Solution

MatrixDud earned 500 total points
ID: 8141258
For a CSV file, which will open in Excel all you need to do to format the file is use comma (,) delimiters with a newline at the end. And of course as Tintin posted you need to specify the content-type in the header (not the <head>).

Here's a good page on CSV:

Here's a couple on Content-Types and headers:

Author Comment

ID: 8150884
Application is written in Perl. Any advice how I access the contents of the current html page and ouptu these to Excel or a csv file?

I'm new to Perl, so any example would be appreciated.

Author Comment

ID: 8153036
I've managed to get the export to Excel to work using the 'application/vnd.ms-excel' type (thanks for the help on this!). It is taking too long to download, though - I guess this is because the data has to be read from database, converted to HTML and then converted into Excel format.

I would rather download straight to a csv format, which should be faster and will get over Excel's row limit limitation.

What syntax do I need to do this? Is there a different content-type I can use?

I have a DB connection:
        my $dbh = DBI->connect($DBIPARAM,$user,$password,RaiseError=>1,PrintError=>1})

and a query to run ($query).

Can someone show me a rough outline of the code I need to create a .csv file of data on the client workstation?


Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question