182x Posted July 26, 2007 Share Posted July 26, 2007 hey guys, I was reading a tutorial on PHP and it referes to absolute and relative paths I was just wondering is the following "../test/test2/test.php" classed as an absolute or relative path? The reason I ask is that I always thought it was a relative path but in the tutorial for jpgraph it states that only absolute paths can be used and the above style works. thanks. Quote Link to comment Share on other sites More sharing options...
nicelad_uk Posted July 26, 2007 Share Posted July 26, 2007 From what I understand thats a relative path, an absolute path would have the address in like http://www.yourhostname.com/path1/path2/path3.php. Relative path would be like /path1/path2/path3.php. Someone correct me if Im wrong though Quote Link to comment Share on other sites More sharing options...
Crow Posted July 26, 2007 Share Posted July 26, 2007 Relative paths are paths relative to the file location: <?php include './lib/mysql.class'; ?> If the file is in /var/www then this becomes /var/www/lib/mysql.class If the file moves to /etc/website then this becomes /etc/website/lib/mysql.class Absolute paths are relative to the directory structure, and aren't affected by when the file moves: <?php include '/home/steve/bot/lib/mysql.class'; ?> No matter where the file is located this path is always /home/steve/bot/lib/mysql.class. -Steve Quote Link to comment Share on other sites More sharing options...
182x Posted July 26, 2007 Author Share Posted July 26, 2007 Could this then lead to any problems that I have used a relative path? Although in testing it seems fine. Quote Link to comment Share on other sites More sharing options...
Crow Posted July 26, 2007 Share Posted July 26, 2007 There shouldn't be any problems as long as you keep the paths correct. IE: If you move index.php you have to move the file you're pointing to also. -Steve Quote Link to comment Share on other sites More sharing options...
182x Posted July 26, 2007 Author Share Posted July 26, 2007 Thanks, am I correct in assuming that the ".." in the path means go back back one directory? So if "../../" was used it means go back two directories? Quote Link to comment Share on other sites More sharing options...
Crow Posted July 26, 2007 Share Posted July 26, 2007 Exactly (just as . is current directory) Quote Link to comment Share on other sites More sharing options...
182x Posted July 26, 2007 Author Share Posted July 26, 2007 Thanks Quote Link to comment 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.