Page 1 of 1

Download csv from php

Posted: Wed Apr 15, 2009 3:38 pm
by xionhack
Hello. I have a website done in php. I want to have a hyperlink that when the user clicks on it will download a csv file that would be created in that moment. I've looked in different forums and in the php manual but havent been able to do it. Can somebody help? Thanks!

Re: Download csv from php

Posted: Wed Apr 15, 2009 4:15 pm
by requinix

Code: Select all

<a href="download.php">Download</a>

Code: Select all

<?php // download.php
 
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=filename.csv"); // change the filename
 
// output your CSV content here
 
?>
If you knew to look on the manual page for header you might have seen example #1.

Re: Download csv from php

Posted: Fri Apr 17, 2009 9:24 am
by xionhack
Thanks! Now, how should I output the csv. I just know that it has to be separated by |