I have data in a MySQL database. I am sending the user a URL to get their data out as a CSV file.
I have the e-mailing of the link, MySQL query, etc. covered.
How can I, when they click the link, have a pop-up to download a CVS with the record from MySQL?
I have all the information to get the record already. I just don't see how to have PHP create the CSV file and let them download a file with a .csv extension.
Already very good solution came. I'm just puting the total code so that a newbie get total help
I have saved this code in csv-download.php
Now see how I have used this data to download csv file
So when I have clicked the link it download the file without taking me to csv-download.php page on browser.
php://output
fputcsv
Simple method -
So each line of the
$data
array will go to a new line of your newly created CSV file. It only works only for PHP 5 and later.The easiest way is to use a dedicated CSV class like this:
Instead of:
Use:
Try:
etc
Edit: Here's a snippet of code I use to optionally encode CSV fields: