save file to user comp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

save file to user comp

Post by Think Pink »

hello,
i need help with the following.
I have to export data from a db to a file.csv. So far is ok, but i don't know how i could save the file to users computer.
Could someone pls guide me?
traherom
Forum Newbie
Posts: 13
Joined: Tue Mar 15, 2005 6:43 am

You can't

Post by traherom »

You can't directly. You either have to sent the file data with the appriate header or you have to just out the stuff you their browser and have them copy and paste. I'd do the former, probably like this:

Code: Select all

<?php
// Note that there can be no output (even spaces!) before the next line
header('Content-type: text/cvs');

// Put the cvs file contents here
// Example:
echo "asdf,iojwefioe,wefoiwjef\n";
echo 'wioefje,woefjeifo,jioj';
?>
There is a header you should output to tell the browser what the file is called, but I don't remember it right now.
Post Reply