co.ador Posted March 9, 2010 Share Posted March 9, 2010 include $_SERVER["DOCUMENT_ROOT"] . "/myscript.php"; Absolute? and relative? include file.php what's the difference and how the absolute path works? Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/ Share on other sites More sharing options...
trq Posted March 9, 2010 Share Posted March 9, 2010 Absolute paths are a complete path from the root of your filesystem. Relative paths are relative to your current location. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023576 Share on other sites More sharing options...
Zane Posted March 9, 2010 Share Posted March 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023577 Share on other sites More sharing options...
trq Posted March 9, 2010 Share Posted March 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023579 Share on other sites More sharing options...
co.ador Posted March 9, 2010 Author Share Posted March 9, 2010 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.. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023615 Share on other sites More sharing options...
trq Posted March 9, 2010 Share Posted March 9, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023616 Share on other sites More sharing options...
trq Posted March 9, 2010 Share Posted March 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023618 Share on other sites More sharing options...
Zane Posted March 9, 2010 Share Posted March 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023619 Share on other sites More sharing options...
co.ador Posted March 9, 2010 Author Share Posted March 9, 2010 Hey I was mistaken Lol, I was confusing absolute path with relative path I guess.. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023630 Share on other sites More sharing options...
isedeasy Posted March 9, 2010 Share Posted March 9, 2010 Back to the original example and still in c the relative path to a would be ../b/a. Would it not be ../../? Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023633 Share on other sites More sharing options...
trq Posted March 9, 2010 Share Posted March 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023837 Share on other sites More sharing options...
co.ador Posted March 9, 2010 Author Share Posted March 9, 2010 Thank you guys for the discussion here it makes it clear for me in between a relative and absolute path. Quote Link to comment https://forums.phpfreaks.com/topic/194624-whats-the-differences-in-between-an-absolute-and-relative-paths/#findComment-1023898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.