简体   繁体   English

如何在 HTML 中包含下载属性以链接

[英]How can I include download attribute to link in HTML

I would like to know how to include a download attribute into a link.我想知道如何将download属性包含到链接中。 By that I mean I have this:我的意思是我有这个:

<a href="files/apple.pdf download>Download here</a>

However I would like to include all this into a link and then into QR code and I want to start downloading the file (or ask for download) automatically without clicking anything when someone goes to the site using the link.但是,我想将所有这些都包含到一个链接中,然后包含到 QR 码中,并且我想在有人使用该链接访问该站点时自动开始下载文件(或要求下载)而不单击任何内容。
Thank you谢谢

It's not possible to include option to force download a file from URL in QR code.无法在 QR 码中包含强制从 URL 下载文件的选项。

If you have access to server configuration, you should be able to overwrite file's header so the browser starts downloading it automatically.如果您有权访问服务器配置,您应该能够覆盖文件的 header 以便浏览器开始自动下载它。

For example, in Apache you could put this into your .htaccess file:例如,在 Apache 中,您可以将其放入 .htaccess 文件中:

<Files ~ "\.*$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>

This will force download of every file in a directory.这将强制下载目录中的每个文件。 If you only want to force download specific files you could change the * to some other regular expression like so:如果您只想强制下载特定文件,您可以将*更改为其他一些正则表达式,如下所示:

<FilesMatch "\.(?i:doc|odf|pdf|rtf|txt)$">

or:或者:

<FilesMatch "\.(?i:pdf)$">

Depending on your back end, configuration may differ.根据您的后端,配置可能会有所不同。 Try searching for how to set Content-Disposition and Type headers on your platform.尝试搜索如何在您的平台上设置 Content-Disposition 和 Type 标头。

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

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