如何在网页上显示本地计算机上的图像

如何在网页上显示本地计算机上的图像

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

问题描述

在这种情况下:我在LAN网络上有两台计算机.其中之一是充当Web服务器.当第二个客户端计算机浏览器(Firefox)从服务器发出请求时,它将发送以下html

Here's the scenario: I have two machines on a LAN network. One of them is acting as a web server. When the second, client machine browser (Firefox) makes a request from the server, it sends the following html

<!DOCTYPE HTML>
<html>
<body>
<img src="C:\Users\General\Desktop\map1.jpg" align="middle">
</body>
</html>

但是不显示图像.我已经尝试了img标签的以下变体:

The image however is not displayed. I have tried the following variations to the img tag:

<img src="C:/Users/General/Desktop/map1.jpg" align="middle">
<img src="file:///C:/Users/General/Desktop/map1.jpg" align="middle">
<img src="http://localhost//file:/C:/Users/General/Desktop/map1.jpg" align="middle">

有趣的是,如果我查看页面源并将html内容保存到本地文件,然后在可以正常工作的浏览器中打开它.从服务器获取时,完全相同的html代码不起作用,但是在本地计算机上打开时,它们却起作用.

Funny thing is if I view the page source and save the html content to a local file and open it in the browser it works. The exact same html code does not work when fetched from the server, but works when opened on the local machine.

请注意,我正在尝试从客户端计算机上加载映像,因为在我的方案中无法在服务器计算机上存储映像. (服务器实际上是没有SD卡的Arduino Mega)

Please note that I'm trying to load the image off the client machine because it is impossible to store an image on the server machine in my scenario. (The server is actually an Arduino Mega without an SD card)

推荐答案

在大多数最新的浏览器中,出于安全目的,不会打开指向本地文件(file:///)的链接.在您的情况下,浏览器不会显示硬盘上文件中的图像.这个原因也解释了为什么在本地保存页面时它可以工作.

In most recent browsers, links to local files ( file:/// ) do not open, for security purposes. In your case, the browser does not display an image that resides on a file on your hard disk. This reason also explains why it works when you save your page locally.

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

08-18 10:18