如何执行“将链接另存为”功能只需点击一个链接? [英] How can I carry out the "Save Link As" function with just one click on a link?
问题描述
一种方式,使用 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屋!