Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialZaberca David
5,361 PointsConfusions on a simple thing
In the video, the teachers explains that we must use $_SERVER['DOCUMENT_ROOT'] to access a file absolutely. Why can't we just use a relative-root "/" for the same purpose. What's the difference?
3 Answers
Jeremy Germenis
29,854 PointsIf you move a file into another folder you would have to modify the path which would mess up the file paths on any previous file using that path. As you seem to know this is not the only solution, just the one that fit the situation best.
Jeremy Germenis
29,854 PointsThis is most useful if you are working on a project locally (testing server) and then move it to a hosting service. You will not have to change file paths. It also makes moving file around into different directories easier.
Zaberca David
5,361 PointsWhat if I use a constant like BASE_PATH and everything I target look like this: "/" . BASE_PATH . "imgs/logo.png" I could just change BASE_PATH into whatever subfolder(s) path I have my website in.