如何创建触发文件下载的链接? [英] How to create a link that triggers file download?

查看:135
本文介绍了如何创建触发文件下载的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击下载PDF链接时,我希望下载提示出现,用户可以下载该文件。

When a user clicks a "Download PDF" link, I would like for the download prompt to appear and for the user to be able to download the file.

目前,用户只是转移到PDF文件的地址。

Currently, the user is just transferred to the address of the PDF file.

例如:

<a..[what goes here??]..>Download PDF</a>

似乎有一个JavaScript&

It seems that there's a combination of JavaScript & PHP needed to do this.

推荐答案

p>如果你在Apache,你可以把它放到.htaccess中:

If you're on Apache, you can drop this into your .htaccess:

<Files *.pdf>
  Header set Content-Disposition attachment
</Files>

这将发送所有PDF文档作为下载。 mod_headers 必须启用。

This will send all PDF documents as downloads. mod_headers has to be enabled though.

这篇关于如何创建触发文件下载的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆