3

I'm new to HTML and I had a question about accessing files with pictures. I know that, to access the pictures that are within other folders, the code looks something like what is shown below and my HTML file would be right before the pictures file:

<img src="pictures/mountain.jpg" alt="mountain"/>

My question is: how do I access pictures that are placed in files that are outside of my HTML file? How do I link a picture but backwards through a file that is the file that holds these files?

Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
Kristy
  • 33
  • 3

3 Answers3

3

Do you mean going up a folder?

<img src="../pictures/mountain.jpg" alt="mountain"/>

Also, if you wanted to go up an additional folder you would do this:

<img src="../../pictures/mountain.jpg" alt="mountain"/>
ketchupisred
  • 661
  • 3
  • 16
2

The files you want to refer to in a html file, being images or other html files or JavaScript files, must be within the root of your server. So if the root of your server is c:\users\httpserver and you want to link to an image in c:\users\kristy\pictures\mountain.jpg, the answer is that it is not possible, you will need to copy the file to a Directory within c:\users\httpserver and link it either relatively, as ketchupisred showed or absolutely.

i.e if the html-file is located in c:\users\httpserver\html and the picture is c:\users\httpserver\pictures\mountain.jpg, either

<img src="/pictures/mountain.jpg" alt="mountain"/>

note the starting / that refers to the root of the server or

<img src="../pictures/mountain.jpg" alt="mountain"/>

the .. taking you one Level up before going into the pictures folder

MortenSickel
  • 2,118
  • 4
  • 26
  • 44
0

Since going up one or two folders has already been explained, I'll just add that if you want to access a file in the root directory you can do this:

<img src="/pictures/mountain.jpg" alt="mountain"/>