无需右键单击链接即可下载图像的代码?
问题描述:
我想知道制作链接时需要做什么,点击后,使用另存为对话框下载图像,而不是仅仅在浏览器中加载图像。
我知道MIME编辑可以为我的浏览器执行此操作,但我希望它可以编入我的网站,因为我无法告诉所有用户编辑浏览器的设置
我不想右键点击链接&点击另存为,
,我不想要压缩文件。
&我被告知服务器端语言应该能够做到。
I was wondering what I would need to do to make a link, when clicked, download an image with the Save As dialog box, instead of just loading the image inside the browser.
I know that MIME edit would be able to do this for my browser, but I want it scripted into my web site, because I can''t tell all of my users to edit their browser''s settings
I don''t want to have to right click the link & click save as,
and I don''t want to have to zip the file.
& I was told a server side language should be able to do it.
答
向下滚动到有关内容处理的部分
如何在html链接中获取该内容?
How do I get that in an html link though?
您好。
是的,这可以使用PHP完成。
PHP可以建议浏览器中的页面应该作为指定的文件类型下载,而不是显示为HTML标记。
请注意,并非所有浏览器都足够聪明,可以接受这一点,但大多数主要的浏览器都是。 (上次我检查过,在我通常检查我的代码的所有浏览器中,只有Apple的Safari有一些问题)
(编辑:刚检查过它,看起来它们已修复它:P)
这是通过 header()函数。
设置HTTP标头,作为向浏览器的指示发送,指定了许多内容,其中包括:文件名和类型。
尝试类似:
Hi.
Yes, this can be done using PHP.
PHP can suggest to the browser that the "page" should be downloaded as a specified file type rather than displayed as HTML markup.
Note that not all browsers are smart enough to accept this, but most of the major once are. (Last time I checked, of all the browsers I usually check my codes on, only Apple''s Safari had some issues with this)
( Just checked it and it appears that they have fixed it :P)
This is done, as Markus'' link pointed out, via the header() function.
It sets HTTP headers, which are sent as directions to the browser, specifying a number of things, amongst which are the file name and type.
Try something like:
展开 | 选择 | Wrap | 行号