Forum Moderators: mack
This is probably going to be the newbie question of the year but I'm really battling...
How do I specify the location of images and pages not in the current folder. It was fine when I was using one dir for my images, which was located inside my main site dir.
For example:
<img src="images/footer-logo.jpg">
But now I want to organise it better so I have some pages stored in C:\site\components, the pages in components dir have to access images in C:\site\images
How to I specify this?
[mydomain.com...]
Of course if this is on an intranet, it may not work.
If your images are in the top most level folder/directory like…
[mydomain.com...]
and your page is 2 levels down like …
[mydomain.com...]
then the link should be…
../../images/myimage.gif
Reason…
The 1st ../
would take you to the folder/directoty called ‘one’ and would look for them in …
[mydomain.com...]
The 2nd ../
would take you to the root so it would look for them in …
[mydomain.com...]
<img src="image.jpg">
Linking to a subdirectory
<img src="image_directory/image.jpg">
Linking to a lower directory can be done like this
<img src="../image.jpg">
<img src="../../../image.jpg">
linking to cousin directories is just a combination of the above really, like this
<img src="../../image_directory/image.jpg">
One other of the suggestions...
<img src="/image_directory/image.jpg">
Actually will sometimes not work becasue in a lot of web servers that means to look in the root of the webserver first. If you imagine that you have the following...
C:\mysite (this is your site root)
C:\mysite\image_directory
...and you link from a file in c:\mysite it would work. However if you have...
C:\mysite (this is your site root)
C:\mysite\test
C:\mysite\test\image_directory
...and try it you might find it cannot find the file.
Remeber as well that any link from the header file will be realitive to that file and not to the original calling file, that one keeps coming back to put me off time and time again with the way css is organised on our intranet servers.
- And before anyone else posts about it, yes I have mixed up style and content by using the quote UBB command instead of code to highlight the code but I really prefer thos elillte boxes :)
I've got it working perfectly now. Of course that's only locally... hope it still works when I finally upload it.
One last question:
I always thought it made more sense to use relative (I think they're called?) links. But now you say there coupld be problems. Would you guys suggest changing them to absolute links?
The third option is to use a base url value, this would give you one set directory for the whole site that you could use absolute addresses from. I know many who use this and swear by it and I can see why, but the only problem I have ever had with relative linking is when I have complicated folder structures (3-4 levels) and forget where I am.
Plus it has allowed me in the past to pull up a whole new second copy of part of the site in a test directory without having to alter any links so I can view it online and then simply dump it back in place later.
Similarly, if you want to change something from one directory to another, say
mysite.com/widgets/blue/page.html
to
mysite.com/widgets/blue/deep_blue/page.html
you're going to have to rewrite all those image links.
So this:
<img src="image_directory/image.jpg">
should be:
<img src="/image_directory/image.jpg">
the initial "/" will always retrieve the resource from the context root.
Also, if you use "../" you are also retrieving resources relative to your current folder. (Not to mention that when I did that last year the security chief told me in no uncertain terms that this had security implications and I was NOT to do this ever again).