Html src绝对路径问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5157772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:02:49  来源:igfitidea点击:

src absolute path problem

htmlimagesrcabsolute-path

提问by luca

I have an image in C:\wamp\www\site\imgand i try to display it in a page with this:

我在C:\wamp\www\site\img 中有一个图像,我尝试在一个页面中显示它:

<img src="C:\wamp\www\site\img\mypicture.jpg"/>

but it's not working.The file is actually there and if I try to refer to it with a relative path i got the picture

但它不起作用。文件实际上在那里,如果我尝试使用相对路径引用它,我会得到图片

<img src="../img/mypicture.jpg">

where is the error?what am I missing?? thank you again guys!

错误在哪里?我错过了什么?再次感谢你们!

采纳答案by rlb.usa

You should be referencing it as localhost. Like this:

您应该将其引用为localhost. 像这样:

<img src="http:\\localhost\site\img\mypicture.jpg"/>

<img src="http:\\localhost\site\img\mypicture.jpg"/>

回答by Luke Duddridge

I think because C would be seen the C drive on the client pc, it wont let you. And if it could do this, it would be a big security hole.

我想因为 C 会在客户端电脑上看到 C 驱动器,所以它不会让你看到。如果它可以做到这一点,那将是一个很大的安全漏洞。

回答by forzagreen

<img src="file://C:/wamp/www/site/img/mypicture.jpg"/>

<img src="file://C:/wamp/www/site/img/mypicture.jpg"/>

回答by leonbloy

Use forward slashes. See explanation here

使用正斜杠。请参阅此处的说明