-5

I have a img tag with src = "file:///C:/Users/king/Documents/testing.jpg". This tag is not showing the image . Whats the problem ?

King Kong
  • 2,855
  • 5
  • 28
  • 39

7 Answers7

3

img tag doesn't have a href attribute.. that's for links.

  • Use src="image path here" instead. The full tag is <img src="path" alt="alt text" />
  • Make sure the path leads to a valid file
  • Put the path in quotes
  • Know that it will display a file from your computer and this will only work if the HTML page is locally stored on your computer.
sachleen
  • 30,730
  • 8
  • 78
  • 73
1

The problem might be arising because the address that you have goes to a file on your computer. If someone else is trying to access this page from a webserver, they most likely will not have your file at that same location on their computer.

FlyingMolga
  • 1,498
  • 1
  • 14
  • 22
1
<a href="file:///C:/Users/King/Documents/testing.jpg"><img src="file:///C:/Users/King/Documents/testing.jpg" /></a>

Must work

Be sure if testing.jpg is there.. Maybe is testing.JPG ..

AlecsMih
  • 11
  • 1
0

<img src="FILE"> is the correct format.

imakeitpretty
  • 2,108
  • 5
  • 16
  • 16
0

<img src="path/to/file.jpg" alt="This is my image" />is a correct tag...try that instead And you cant use a local path like that, it goes to a file on your harddrive, nobody else can access it if you put it online. Use a relative link instead like "rootfolder/images/yourimage.jpg"

JOSEFtw
  • 9,781
  • 9
  • 49
  • 67
0

Due to security reasons, I'm not sure if a browswer can always access a protocol of file:// are you running on localhost? If not that is your reason. I would advise you to always use relational URLS if possible so if your HTML is in Documents then src="testing.jpg" would be fine.

In general I would recommend having the images in a subfolder of where your index file is to make it easier and to allow relative urls such as "./images/testing.jpg" or "../images/testing.jpg".

Travis Pessetto
  • 3,260
  • 4
  • 27
  • 55
0

use relative paths as opposed to absolute for example if the image file was to folders above where the place you are storing your webpage at use ../../testing.jpg

John
  • 1,556
  • 4
  • 26
  • 42