Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

html - How to create downloadable link to text file?

The purpose is to download the dumped backup.sql file after running the sql dumping script (from PHP). Normally, the dumped .sql file is outputted (written) on the server. Then when i make a href link to that file like <a href="backup.sql">Download File</a>, the file is opening inside the browser on clicking, instead of being downloading.

  • i just want to make a simple HREF LINK (to such a text file) which show up with "Save as.." dialog on simple Left Click.

How it could be done?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Or you could just use the new HTML5 property download in the anchor tag of your html.

The code will look something like

<a download href="path/to/the/download/file"> Clicking on this link will force download the file</a>

It works on firefox and chrome latest version. Should I mention that I didn't check it in IE? :P


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...