How to implement click-to-download file function in html

王林
Release: 2020-08-12 16:46:42
forward
4505 people have browsed it

How to implement click-to-download file function in html

Use the a tag to complete the click-to-download file function

<a href="/user/test/xxxx.txt" download="文件名.txt">点击下载</a>
Copy after login

In this way, when the user opens the browser and clicks the link, the file will be downloaded directly.

(Recommended tutorial: html tutorial)

But there is a situation, such as txt, png, jpg and other files that the browser supports to open directly will not be downloaded Instead of doing the task, the file will be opened directly. At this time, you need to add an attribute "download" to the a tag.

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="http://171.188.96.**:****/d/c833945c11/files/?p=/plugins.maintain.CheckLinePartTask/cebab687-6dc5-4128-b7d9-8bc2fe369598.png&raw=1"
download="test.png">点击下载</a>
</body>
</html>
Copy after login

The attribute after down is the file name of the downloaded file.

The above is the detailed content of How to implement click-to-download file function in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template