使链接提示“另存为”的简单方法
是否有一种快速内联方式,可以使我的某些链接在第一次初始单击后提示“文件另存为”(与右键单击相同的屏幕)?
Is there a quick inline way, to make some of my links prompt 'save file as' (Same screen as right click) after the first initial click?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要发送适当的标头即可。
Content-Disposition
是关键(请参阅 http://en.wikipedia.org/维基/MIME)。请参阅下面的 PHP 示例。
You simply need to send appropriate headers.
Content-Disposition
is the key (see http://en.wikipedia.org/wiki/MIME).See PHP example below.
在 php 方面,您真正需要的是将
Content-Disposition
标头设置为附件,如header('Content-Disposition:attachment; filename=name-of-file') ;
。如果您必须或想要在客户端执行此操作,浏览器将自动尝试下载大量文档类型,因此您只需提供指向它的直接链接即可。不过,显然这不会发生在你身上,所以它当然不可靠。What you really need on the php side is to set the
Content-Disposition
header, to attachment, as inheader('Content-Disposition: attachment; filename=name-of-file');
. If you have to or want to do it on the client side, browsers will automatically attempt to download a lot of document types, so you can just provide a straight link to it. Apparently this is not happening for you, though, so of course it's not dependable.