Can I configure an HTML button to always “save tar

2019-09-16 02:51发布

问题:

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!

回答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



回答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);
}
?>