Use the a tag to complete the click-to-download file function
<a href="/user/test/xxxx.txt" download="文件名.txt">点击下载</a>
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>
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!