如何在HTML网页上显示放置在客户机上的本地图像 [英] How to display local images placed on client machine in HTML webpages

查看:166
本文介绍了如何在HTML网页上显示放置在客户机上的本地图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Web服务器上托管的HTML网页上显示放置在客户端机器上的本地图像

我在 C: / Images 文件夹,所以路径应该是 file:/// C:/Images/1.jpg 对于图片1.jpg



我使用< img src =file:/// C: sample.html中的/images/1.jpg/>


$ b sample.html放置在本地硬盘时,显示 1.jpg ,但是当我把 sample.html 文件放在一个web服务器上时,它不会显示放在我的C上的图像:drive。



有什么方法可以显示放置在Web服务器上的HTML网页上放置在客户端硬盘上的图像吗?

我尝试了即使iframe,但没有运气。

编辑:可以使用userscript或Firefox插件显示这些图像吗?我实际上在我的屏幕保护程序firefox addon中实现了这个功能。

解决方案

不允许网页访问file:// / URL出于安全原因,没有办法解决这个问题。但是,如果您通过其他协议使相同的文件可访问 - 这可以工作。例如,您可以将以下行放入您的加载项的 chrome.manifest 文件中:


资源myaddon file:/// C:/ Images

这将创建一个资源协议别名指向该目录 - 资源协议可以被网页使用。这意味着页面将能够使用 C:\Images\1.jpg 作为 resource://myaddon/1.jpg



您也可以动态添加资源协议别名。只要确保你只能以这种方式访问​​图像,而不是所有的磁盘内容 - 否则你可能会打开一个安全漏洞。


How to display local images placed on client machine in HTML webpages hosted on a webserver

I'm having few images placed in C:/Images folder so path should be something file:///C:/Images/1.jpg for a image 1.jpg

I'm using the code <img src="file:///C:/Images/1.jpg" /> in sample.html

sample.html when placed on local HDD, shows 1.jpg, but when I put the sample.html file on a web server it doesn't display the image placed on my C: drive.

Is there any way to show images placed on client HDD from a HTML webpage placed on a web server?

I tried even iframe, but no luck.

EDIT: Can I show these images using userscript or firefox addon? I'm actually implementing this thing in my screensaver firefox addon.

解决方案

Web pages aren't allowed to access file:/// URLs for security reasons, there is no way around this. However, if you make the same files accessible via another protocol - this can work. For example, you can put the following line into your add-on's chrome.manifest file:

resource myaddon file:///C:/Images

This will create a resource protocol alias pointing to that directory - and the resource protocol can be used by webpages. Meaning that the pages will be able to use the image C:\Images\1.jpg as resource://myaddon/1.jpg.

You can also add resource protocol aliases dynamically. Just make sure you make only images accessible in this way and not all disk content - you might be opening a security hole otherwise.

这篇关于如何在HTML网页上显示放置在客户机上的本地图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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