Page 1 of 1

save file to user comp

Posted: Sun May 15, 2005 4:16 pm
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?

You can't

Posted: Sun May 15, 2005 7:12 pm
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.