简体   繁体   English

单击链接后如何触发“另存为”弹出窗口? 具体来说,我如何触发比MIME类型更改?

[英]How do I trigger a save as pop-up on clicking of a link? Specifically, how do I trigger than MIME type change?

I've read the following question: save file onclick 我已阅读以下问题: 保存文件onclick

I understand what it's saying, but I don't understand how I'd make that work for an arbitrary file. 我明白这是在说什么,但我不知道如何使该文件适用于任意文件。 Would I set the href attribute equal to a PHP script with that information? 是否将href属性设置为等于具有该信息的PHP脚本?

Would it be POST or GET? 是POST还是GET? Can I specify? 我可以指定吗? What method within the script would I use to retrieve the filename? 我将使用脚本中的哪种方法来检索文件名?

The method of the request has little to do with it. 请求的方法与它无关。 Your request will trigger a response from the server which in turn serves up the file. 您的请求将触发服务器的响应,服务器随后将提供文件。

It could be a something like www.site.com/serveFile.php?file=foo.txt . 可能类似于www.site.com/serveFile.php?file=foo.txt Where you are specifying the file to serve up as a GET parameter. 在指定文件作为GET参数的位置。

Then in code you could retrieve the file name (or some numeric identifier, or some date range used in retrieving data from the database to serve up CSV content), use that variable, generate content, set the headers. 然后,在代码中,您可以检索文件名(或一些数字标识符,或从数据库检索数据以提供CSV内容时使用的某些日期范围),使用该变量,生成内容,设置标题。 All there is to it. 一切都在这里。 Think the post you linked explains the mechanics of serving the content with the correct disposition for a download (save as). 认为您所链接的帖子说明了以正确的方式进行下载(另存为)来提供内容的机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM