< Img src =" C:/users/john/downloads/download.png">从我的本地驱动器不工作......? [英] <Img src="C:/users/john/downloads/download.png"> from my local drive is not working...?

查看:121
本文介绍了< Img src =" C:/users/john/downloads/download.png">从我的本地驱动器不工作......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,



我对html中的img标签有点怀疑。实际上,我在记事本中尝试了相同的代码,图像显示完美。



但我在项目页面中尝试过相同的代码,例如student.html页面。在那里我使用了相同的代码,但没有加载已在控制台中显示的图像。为什么这个图片没有加载到我的页面我已经给了我所尝试的整个代码请告诉我,如果有人知道





记事本:

< html> 
< body>

< h1> hi< / h1>
< h1>新图片< / h1>
< img src =C:/Users/john/Downloads/download.png\"alt =\>


< / body>

< / html>





我的尝试:



这在记事本中非常完美。但是没有在我的项目html页面中使用相同的代码

解决方案

我相信你错过了文件://代码之前的路径所以它应该是file:// c:/Users/john/Downloads/download.png



你还应该确保你只想这样做暂时用于本地html文件而不是托管在某处的文件。设计一个页面并将所有图像放在正确的位置要好得多,这样你就可以使用src值的参考映射。



例如.. 。

您的网站位于c:\Users\John \Downloads \ TestSite

创建一个名为images的子文件夹并将图像download.png复制到该文件夹文件夹。

现在,您可以将IMG标记设置为

 <   img     src   =  / images / download.png    /  >  


首先,将结束标记更改为/>来自\>



缺少显示可能是因为网页没有从您的用户ID运行,因此访问Users / john 可能被拒绝了。尝试将图像移动到中性文件夹,该文件夹对所有用户具有完全访问权限,并且可能会修复它。


您正在为图像指定本地路径。即使浏览器允许您将本地文件加载到页面(他们没有),它也会尝试从用户的文件系统加载该图像。 />


用户不太可能拥有与服务器上的文件具有相同路径和文件名的文件。即使他们这样做了,也不会是同一个文件。



但这无关紧要,因为浏览器不允许网站来自用户本地文件系统的引用文件。出于安全原因,这是为了防止恶意网站在您不知情的情况下阅读您计算机的内容。



相反,您需要使用HTTP加载图像或HTTPS路径。这可以是完整URL,当前站点上的绝对路径,也可以是相对于当前页面的路径。例如:

 <! -    完整网址:   - >   
< img src = http://www.yoursite.com/images/download.png alt = / >

<! - 绝对路径: - >
< IMG < span class =code-attribute> src = / images / download.png alt = / >

<! - 相对路径: - >
< img src = ../ images / download.png < span class =code-attribute> alt = / >


hi friends,

i have little bit doubt for img tag in html . actually i was tried this same code in Notepad there that image was shown perfectly.

but this same code i was tried in my project page like student.html page. there i have used this same code but the image was not loaded which has shown in console . why this image has not loaded in my page i have given entire code what i have tried please tell me if anyone knows


Notepad:

<html> 
<body>

<h1>hi </h1>
<h1>New Image</h1>
 <img src="C:/Users/john/Downloads/download.png" alt="" \> 


</body>

</html>



What I have tried:

this was working perfect in notepad. but not working in my project html page using this same code

解决方案

I believe you are missing the file:// code before the path so it should be "file://c:/Users/john/Downloads/download.png"

You should also ensure that you are only wanting to do this temporarily for a local html file and not one that is hosted somewhere. It is far better to design a page and have all the images in the right location so that you can use the referential mapping for the src values.

For example...
Your website is located in c:\Users\John\Downloads\TestSite
Create a subfolder called images and copy the image download.png to that folder.
Now you can set your IMG tag to be

<img src="/images/download.png" />


First, change the closing tag to "/>" from "\>"

The "lack of display" is probably that the webpage is not being run from your user ID, so access to "Users/john" is probably being denied. Try moving the image to a "neutral" folder that has full access permissions for all users and that will probably fix it.


You are specifying a local path for the image. Even if the browser allowed you to load local files into your page (they don't), it would be trying to load that image from the user's file system.

It's highly unlikely that the user will have a file with the same path and filename as the file on your server. And even if they did, it's not going to be the same file.

But that's irrelevant anyway, because browsers do not allow websites to reference files from the user's local file system. This is for security reasons, to prevent a malicious site from reading the contents of your computer without your knowledge.

Instead, you need to load the image using an HTTP or HTTPS path. This can either be a full URL, an absolute path on the current site, or a path relative to the current page. For example:

<!-- Full URL: -->
<img src="http://www.yoursite.com/images/download.png" alt="" />

<!-- Absolute path: -->
<img src="/images/download.png" alt="" />

<!-- Relative path: -->
<img src="../images/download.png" alt="" />


这篇关于&lt; Img src =&quot; C:/users/john/downloads/download.png&quot;&gt;从我的本地驱动器不工作......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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