You can just make a hyperlink with its href to a regular file, your browser will prompt to download it.
As for renaming the file, all you could do is create a special page which sends the file contents and correct headers, and specifying another name. You'll have to send the content-disposition header, as such:
发布评论
评论(3)
您只需使用其 href 建立一个指向常规文件的超链接,您的浏览器就会提示下载它。
至于重命名文件,您所能做的就是创建一个特殊页面来发送文件内容和正确的标头,并指定另一个名称。您必须发送
content-disposition
标头,如下所示:You can just make a hyperlink with its href to a regular file, your browser will prompt to download it.
As for renaming the file, all you could do is create a special page which sends the file contents and correct headers, and specifying another name. You'll have to send the
content-disposition
header, as such:您可以发送 Content-disposition 标头来强制文件下载框并指定默认文件名。
http://support.microsoft.com/kb/260519
You can send a Content-disposition header to force a file downlaod box and specify a default filename.
http://support.microsoft.com/kb/260519
关于编辑文件名:
HTML5 为
a
标签引入了一个新属性:download
。使用它会强制支持该属性的浏览器提示文件下载,而不是导航到或尝试打开链接的文件。
此外,您分配给
download
的任何值都将替换文件的实际名称。源代码和演示: http://updates.html5rocks.com /2011/08/在 HTML5-a-download 中下载资源
In regards to editing the filename:
HTML5 introduces a new attribute for
a
tags:download
.Using it forces browsers that support the attribute to prompt for a file download, rather than navigating to or attempting to open the linked file.
Also, whatever you value you assign to
download
will replace the file's actual name.Source and demo: http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download