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 2067
灰色年华
灰色年华 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:24

    Yeah, there is. It does require specifying some headers. Exactly how it works depends on what language you're using, but here's an example using php, taken off of php.net:

    
    

    Basically, first we tell the client what type of file we're sending, then we tell the client that what we're sending is an attachment, and it's name, instead of it being a page to display, and then finally we print/read the file to the output.

    Given that you're already using php to generate the xml file, I would suggest adding the header commands above to the code that generates the xml file, and see if that does the trick.

提交回复
热议问题