0

I'm generating CSV files in an application I'm doing.

Right now I'm displaying the finished files as plain HTML links, but I would like to make them buttons.

Question:
Is it possible to configure a button so it triggers the "right click & save target as" action, because clicking on the button will try to load the CSV file in the browser.

If not, is there another way to prevent the button target being clicked and maybe display an alert, so the link is not being followed.

Thanks!

frequent
  • 27,643
  • 59
  • 181
  • 333

2 Answers2

2

You can force download using PHP

<?php
header('Content-type: application/force-download');
$musicfile=$_GET["musicfile"];
if(file_exists($musicfile))
{
header('Content-Disposition: attachment; filename="'.$musicfile.'"');
readfile($musicfile);
}
?>
Eric
  • 31
  • 5
1

I'm not sure how you plan to do this without some server help, but you could take a look at this and see if it helps you get somewhere http://www.jtricks.com/bits/content_disposition.html

Luke
  • 2,053
  • 1
  • 18
  • 25
  • Thanks. I'll have a look. Right now I'm just trying to prevDefault() the button when it's being clicked and alerting the user this is a download only button – frequent Jul 30 '12 at 16:57