38

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

<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!

skaffman
  • 398,947
  • 96
  • 818
  • 769
luca
  • 36,606
  • 27
  • 86
  • 125
  • `` maybe will work if on same machine – KJYe.Name Mar 01 '11 at 17:11
  • 1
    @kjy112 No. See @Luke's answer. – rlb.usa Mar 01 '11 at 17:12
  • 1
    @rlb.usa if it's on same local machine it should work. – KJYe.Name Mar 01 '11 at 17:21
  • I'm COMPLETELY new to programming and web design. Got here for I had the same problem that stated in the question. I had the image in another disk other than C, so it did not work.- After some research, and taking a look at the adress bar, I noticed some extra slashes, and now I can see the image where it's supposed to be.- Just in case someone might find it useful: Oh, by the way, I guess there is not a 'localhost' for I am not using one, the html file is on same disk, but it's not -yet- on a server(He, have no idea how to do it! =D).- Thanks to everyone – Robergto Nov 11 '15 at 17:50

5 Answers5

18

You should be referencing it as localhost. Like this:

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

rlb.usa
  • 14,942
  • 16
  • 80
  • 128
  • 1
    thanks i used your suggestion but with forward slashes and now i have my image..but i was wondering why for example my css referenced with "c:\wamp\www\site\css\mycss.css" works instead?? – luca Mar 01 '11 at 17:26
  • 8
    Never use backward slashes in urls – leonbloy Mar 01 '11 at 18:59
  • 5
    (late comment, i know) Simply because the protocol is wrong, there is no `C:` protocol. You could have used the `file://` protocol instead if you really wanted to (not necessarily `http://`localhost), and yes, no backward slashes as leonbloy said – Teodor Sandu Dec 16 '13 at 08:15
  • is there any way i could catch or know that image is broken? – Muneem Habib Sep 18 '15 at 16:33
  • @MuneemHabib See here http://stackoverflow.com/questions/92720/jquery-javascript-to-replace-broken-images – rlb.usa Sep 18 '15 at 17:04
12

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

forzagreen
  • 2,509
  • 30
  • 38
12

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.

Luke Duddridge
  • 4,285
  • 35
  • 50
  • what do you mean? explain please – luca Mar 01 '11 at 17:16
  • If you reference things from C drive; for one the file would need to be located in the same location on everyone's pc. I'm not saying that what you want to do was a big hole, but imaging if you were able to start up command prompt, by linking to it via the C root. – Luke Duddridge Mar 01 '11 at 17:27
  • I got it Luke thanks!now I was wondering why i didn't encounter the same problem with my css file referenced the same using my "C drive" – luca Mar 01 '11 at 17:32
  • 1
    You might have to do some research on that, but I think it has something to do with how the page is rendered, objects defined in the header section are rendered pre the page load, so although you are asking for c:\xxx.css it is actually being found as if on the server, am waffling might not be even close :). I have another suggestion, if you want to have absolute links you can reference your images via from the root of your IIS by the following: `src="/site/img/mypicture.jpg"` – Luke Duddridge Mar 02 '11 at 09:03
2

Use forward slashes. See explanation here

Community
  • 1
  • 1
leonbloy
  • 73,180
  • 20
  • 142
  • 190
1

First open the image in any web browser. Then copy the path and add it as image source location like this :

src="file:///C:/wamp64/www/site/img/mypicture.jpg"
narcis dpr
  • 939
  • 2
  • 12
  • 32
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 14 '21 at 05:31
  • File path should be relative path which doesn't include drive path. – Dipten Sep 14 '21 at 08:03