Is there a way to force the user to download a file from a href link rather than to open it in a browser window?

前端 未结 5 2069
灰色年华
灰色年华 2020-12-11 07:47

Basically I wrote a script that generates a xml file based on user input. After the file is generated a download link appears like so:



        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 08:20

    If you happen to be using Apache for your web server, and you always want to force downloading of XML files, there is a more efficient way to do what @chigley suggested. Just add the following to a .htaccess file.

    
    ForceType application/xml
    Header set Content-Disposition attachment
    
    

提交回复
热议问题