Jump to content

What's the differences in between an absolute and relative paths?


co.ador

Recommended Posts

Think of it like this....

 

Absolute path of an image... broken down into ....... words

- Go to this particular domain name

- Go to this folder... and any subfolders

- Access the image file

 

Relative path of an image .. broken down

  - Is the image in the same folder?  Yes? No?

  - If not... is it in a folder (or subfolder) within the current folder? Yes? No?

  - If not... is the image somewhere above the current folder...

 

 

In short.. an absolute path is setup so that you can use images/links/media/whatever ANYWHERE

A relative path is setup such a way so that you tell it exactly where it is on the current server.  Is it here, is there, is it above below...  To make things easier... relative paths don't have domain names in them.

Link to comment
Share on other sites

I should refine my response.

 

Absolute paths are a complete path from the root of your filesystem (or the root of your web server if the files are being requested by a browser).

 

Relative paths are relative to your current location.

Link to comment
Share on other sites

I understand relative but absolute means that if there is two files of the same name withing the scope of the root directory then it will display both of them?

 

I guess absolute path it just a quick way to dirrect php to look for a file without specifying the exact location.

 

 

Correct me if I am wrong on the last sentence..

 

Link to comment
Share on other sites

Completely wrong. An absolute path is (as the name implies) the complete and absolute (full) path to a file from the root of your filesystem (or web server if your talking about paths to images etc etc within html).

Link to comment
Share on other sites

Given the following directory structure....

 

[pre]

a

`-- b

    `-- c

        `-- d

            `-- e

[/pre]

 

The absolute path to d is /a/b/c/d. While if your in c the relative path to e would be d/e (note the missing forward slash). If you tried the same but with a forward slash (eg /d/e) you would be again looking at an absulute path from the root of the fielsystem (/).

 

[pre]

d

`-- e

[/pre]

 

Back to the original example and still in c the relative path to a would be ../b/a. One more, if your in b the relative path to e would be c/d/e while the absolute path would still be /a/b/c/d/e

 

Simple.

Link to comment
Share on other sites

What?..  maybe you're right.. idk. But absolute and relative are exactly as thorpe said in his refined response

 

A relative link .. is relative to its current location.  Meaning... when you create a relative link, you are branching FROM that page.  In other words.. How many steps does it take to get to your link.  If I'm at page A and I want to link to page B which is 5 folders above it; the link would look like this

../../../../../pageB

If the link is 5 folders below then it would be something like this

f1/f2/f3/f4/f5/pageB

 

In an absolute link.. it doesn't matter how many folders there are above or below pageA, because you're gonna have to put them ALL.  For example

http://domain.com/f1/f2/f3/f4/f5/pageB

Alot of times you'll see links with the slash at the beginning.  That is absolute as well.

/wwwrootFolder/f1/f2/f3/f4/f5/pageB

 

That's probably about as clear as I can make it

 

 

EDIT: jeez.. thorpe beat me to it.

Link to comment
Share on other sites

 

Back to the original example and still in c the relative path to a would be ../b/a.

Would it not be ../../?

 

Yes it would be sorry. Was very late last night (this morning) when I posted. Well spotted. My code would go to a directory called a within a directory called b within the original examples b directory.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.