如何执行“将链接另存为”功能只需点击一个链接? [英] How can I carry out the "Save Link As" function with just one click on a link?

查看:550
本文介绍了如何执行“将链接另存为”功能只需点击一个链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,正如大多数人可能知道的那样,当您在网页上放置文件链接时,必须右键单击该链接,然后单击保存链接为下载文件。我想知道是否有方法可以点击链接并自动下载文件。

解决方案

一种方式,使用 header()调用指定 Content-Disposition



例如,我有一个图像下载脚本,如下所示:

  header(Content-Type: $哑剧); 
header(Content-Disposition:attachment; filename = \foobar.baz\);
readfile($ filename);

您需要找出文件的MIME类型(并使用 Content-Type:$ mime ,使用 Content-Disposition 标题告诉浏览器这个文件是一个附件,然后输出文件与 readfile()



本教程有关于此问题的更多信息。


So, as most of you may know, when you put a link to a file on a webpage, you must right-click the link and click "save link as" to download the file. I wanted to know if there is a way to just be able to click the link and automatically download the file.

解决方案

There is a way, using header() calls to specify Content-Disposition.

For example, I have an image download script that looks like this:

header("Content-Type: $mime");
header("Content-Disposition: attachment; filename=\"foobar.baz\"");
readfile($filename);

You need to find out what the MIME type of the file is (and set it using Content-Type: $mime, tell the browser this file is an attachment using the Content-Disposition header, and then output the file with readfile().

This tutorial has some more information on the matter.

这篇关于如何执行“将链接另存为”功能只需点击一个链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆