PDA

Click to See Complete Forum and Search --> : NightmareWeaver! What is going on with relative paths???


alexjamesdf
02-23-2007, 03:28 PM
Hi there people, I'm hoping someone can help me with this most basic of concepts I am now very confused with.

Relative paths:. When you insert an image onto a web page it should create a path relative to where the document is yes? Hence if your website is called

dreamweaveriskillingme.com and the index.html page has an image on it stored in the same directory, the document path for this image should be simply "/imagename.jpg"...

Now if you have a subdirectory named testing,

dreamweaveriskillingme.com/testing/

and you have an index.html page inside 'testing' and it uses an image in the same directory the path should be "/imagename.jpg" yes? This is what I thought anyway, and when I test it locally it works fine, but when its uploaded this happens:

http://www.joeldevlin.com/testing/

the image path is "/023.jpg" because the image is in the same directory as the index.html...

The image is definitely there on the server:

http://www.joeldevlin.com/testing/023.jpg

So why is it a broken link?

I'd really appreciate some help on this, I just dont understand whats going on and I've never had this problem before.

Cheers

chris_bcn
02-23-2007, 04:31 PM
if the path is /023.jpg then it is looking at the root folder

http://www.joeldevlin.com/023.jpg (http://www.joeldevlin.com/testing/023.jpg)

You could just use absolute paths

alexjamesdf
02-23-2007, 04:36 PM
Thanks for this, but why is it looking from the root folder, I though relative paths are relative to where the document is, not relative to the root? I'm sure other sites do not look from the root folder? What about enourmous sites that must be tested inside a 'test' folder before they go live, they should be insertable at any depth surely? There must be a way of doing this!

Thanks again for your reply though, at least this gives me a backup solution.

John G
02-23-2007, 06:56 PM
for same & relative directory it's:

"./picture.jpg" <--remember the period

for an image in a folder below the files directory:

"./images/picture.jpg"

Now if your html is in
http://www.something.com/test/index.html
and your image is in
http://www.something.com/images/picture.jpg

you would reference:

"../images/picture.jpg" <-- two periods = you go back a directory

(and those "../" can stack so say if you wanted to go back three directories it would be "../../../images/picture.jpg")

All this gets really fun when you start using asp or php html and includes :)

chris_bcn
02-23-2007, 09:56 PM
it's far easier to drill from the root

/test/blah.jpg
to/test/hello/blah.jpg

etc.

that way you don't have to think how deep your are in the site structure

alexjamesdf
02-24-2007, 12:05 AM
I never seen any of this before and I been doing this for a while. Thanks.

I found out also that if you put "/" preceeding the path (ie: /images/image.jpg) it means its site-root relative. If you put without "/", (ie: images/image/jpg) it means that its 'document relative' and that is what I want. However, for some reason dreamweaver is automatically instering the "/" for every path meaning when its uploaded, the site does not work.

Great! Cheers, nightmare weaver

chris_bcn
02-24-2007, 12:36 AM
you can change that in DW preferences.

Don't blame the tool :p

alexjamesdf
02-26-2007, 01:34 AM
Thanks guys, sorry about that last message by me, it sounds like I'm being rude or unappreciative,that was unintentional,(!) just not reading it through before i posted - silly me. Thanks so much for your advice, its a great forum this. I still cant work out how to change these settings but I'm sure I'll find it some day. Cheers, and have a great week. big love Alex

cj2a
02-26-2007, 02:16 AM
I believe if you go to your "Manage Sites" option, choose to "Edit" the site you're working on, and there you have a pair of radio buttons to choose links relative to document, or site root. I had the same problem when I inadvertently had "site root" chosen and for the longest time had to contend with the extra "/" on my images and links. Good luck.