I have produced a custom solution in WordPress which will produce a CSV file to become downloaded by clicking an easy hyperlink, linked straight to this file. Rather than being motivated to download the file to the pc the CSV opens within the the browser window rather.
FWIW I am on Media Temple utilizing a vanilla install of WordPress.
Send the correct mime type
And employ this content-Disposition header to inform it to download: http://www.jtricks.com/bits/content_disposition.html
header('Content-Disposition: attachment; filename="mycssfile.csv"');
You usually wish to send the correct mime type, otherwise fire walls, anti-virus software plus some browsers might have difficulties with it...
You should use PHP's
header() function to alter Content-type
header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename="myFile.csv"');
The above mentioned code will pressure a prompt towards the user for download. where
myFile.csv ought to be changed with the road to the file you would like downloaded.
$filename = 'export.csv'; header('Content-type: application/csv'); header('Content-Disposition: attachment; filename='.$filename);
Also, Personally, i don't like links on my small sites, I love buttons. If you prefer a button to complete for that export function you should use the code below. I simply thought I'd publish it since it required me a little to determine the very first time :)
<input type="button" value="Export to CSV" onClick="window.location.href='something.php?action=your_action';"/>
You have to send the browser a MIME kind of
application/csv therefore it will offload down to handling the file to regardless of the OS suggests (or user selects).
In PHP (before any output is distributed towards the client):