Abo*_*asy 37
使用标记内的download属性<a>
<a href="content/file.pdf" download > pdf link </a>
<a href="content/file.doc" download > doc link </a>
Bir*_*ird 31
在HttpResponse标头中设置Content-Disposition:
Content-Disposition = 'attachment; filename=filename.pdf'
Run Code Online (Sandbox Code Playgroud)
Bal*_*usC 14
这需要在服务器端完成.你不能在客户端这样做.
怎么做取决于有问题的服务器端语言.
PHP:
header('Content-Disposition: attachment; filename="' . $filename . '"');
Run Code Online (Sandbox Code Playgroud)
Java的:
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
Run Code Online (Sandbox Code Playgroud)
.净:
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
Run Code Online (Sandbox Code Playgroud)
如果没有任何服务器端代码可以流式传输PDF文件,那么您需要在Web服务器级别进行配置.在例如Apache HTTPD中,您可以.htaccess使用以下条目在PDF文件夹的根目录中放置/扩展文件:
<Files *.pdf>
Header set Content-Disposition attachment
</Files>
Run Code Online (Sandbox Code Playgroud)
或者在httpd.conf文件中全局配置它.IIS与web.config文件存在类似的方法.
对于IIS:
将要强制下载的所有文件放在自己的文件夹中.
然后在IIS中转到该文件夹并双击HTTP Response Headers.
使用以下信息添加新标头:
名称:内容配置
价值:附件
访问该文件夹中的所有文件时,应提示相应浏览器的"另存为"对话框.