CSV file upload is not requested
I created my own solution in WordPress that will generate a CSV file that will be uploaded by clicking on just a hyperlink linked directly to that file. Instead of asking you to download the file to your computer; CSV opens in a browser window.
FWIW I'm in Media Temple using a vanilla WordPress installation.
a source to share
Send the correct mime type
header('Content-type: text/csv');
And use the Content-Disposition header to tell him to download it: http://www.jtricks.com/bits/content_disposition.html
header('Content-Disposition: attachment; filename="mycssfile.csv"');
You always want to send the correct mime type, otherwise firewalls, antivirus software and some browsers may have problems with it ...
a source to share
You can use PHP function header()
to change Content-type
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="myFile.csv"');
The above code will force you to prompt the user to download. where myFile.csv
should be replaced with the path to the file you want to download.
a source to share
It works:
$filename = 'export.csv';
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
Also, I personally don't like the links on my sites, I like the buttons. If you want the button to do the export function, you can use the code below. I just thought I would post it because it took me a bit to figure it out in the first case :)
<input type="button" value="Export to CSV" onClick="window.location.href='something.php?action=your_action';"/>
a source to share