You can use a content header to instruct the browser to treat output as an attachment
for saving. Use something like the following:
header("Content-Disposition: attachment; filename=filename.csv");
(These *must* be the first lines output by your script)
Then in the body of the script, do something like this:
Note the commas between each value, and also the '\n' which sends a newline to end
each row. If the user is running Windows with Excel installed, they will be given a
choice of opening the file in Excel or saving it.
This works for me using Internet Explorer. Mozilla appends a .txt to the filename (so
you get 'filename.csv.txt'). Does anyone else know how to prevent the .txt being
added by Mozilla?
Hope this helps,
From: Martin E. Koss [mailto:[EMAIL PROTECTED]
Sent: 16 June 2003 13:53
To: [EMAIL PROTECTED]
Subject: Save mySQL data into a CSV file.
I have a table with 1,008 columns in it and at it's peak it has up to 500
rows of data.
I want to enable my client to click on a link and the next thing they are
prompted with is 'Save or Open' (the CSV file).
The data will be compiled into a comma delimited CSV file but rather than be
printed to the screen it would be best if the browser popped up asking where
to save the 'filename.csv' file to. Once saved, the file can be opened in
Excel for analysis.
Where do I start to do this?
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php