Toshiba23 Posted October 24, 2007 Share Posted October 24, 2007 Ok, I'm really confused on how level of files work in PHP in folders... Such as... lets say I have a file in a folder one level below the current folder my script is running in... how do I get to the folder below me? require("../folder_below/file.php"); // Would this work? Also, I noticed phpBB uses phpbb_root_path for ever file requirement it does, I'd like to use that, and I tried... but my server just tells me nothing is there you idiot. Basically, what is the difference between './' and '../' and what are easy ways to get to folders throughout my server? Thankies =) Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/ Share on other sites More sharing options...
Toshiba23 Posted October 24, 2007 Author Share Posted October 24, 2007 Please? =( Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/#findComment-377114 Share on other sites More sharing options...
rajivgonsalves Posted October 25, 2007 Share Posted October 25, 2007 Basically using the ".." and "." for including files is not such a great idea u should create a absolute path using the $_SERVER['DOCUMENT_ROOT'] variable otherwise if you try to include a file in a included file which is in some other location the include might not work "." stands for current directory ".." stands for parent directory Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/#findComment-377637 Share on other sites More sharing options...
Toshiba23 Posted October 26, 2007 Author Share Posted October 26, 2007 Basically using the ".." and "." for including files is not such a great idea u should create a absolute path using the $_SERVER['DOCUMENT_ROOT'] variable otherwise if you try to include a file in a included file which is in some other location the include might not work "." stands for current directory ".." stands for parent directory Why is it a bad idea? Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/#findComment-378863 Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 Basically using the ".." and "." for including files is not such a great idea u should create a absolute path using the $_SERVER['DOCUMENT_ROOT'] variable otherwise if you try to include a file in a included file which is in some other location the include might not work "." stands for current directory ".." stands for parent directory Why is it a bad idea? Many reasons it should be avoided. One it may not be compatible on another server. Two it is not versatile, you cannot take the script and put it in an upper level directory and expect it to work. Finally if you plan on using htaccess for seo and use a "processing" page to include different files etc, you need the absolute path because the relative path is not what you would expect. It is just good practice to use the absolute path over the relative path. Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/#findComment-378864 Share on other sites More sharing options...
Toshiba23 Posted October 26, 2007 Author Share Posted October 26, 2007 How could I find the directory name of a folder I'm in by not including the full path? for example: dirname(__FILE__); gives full path (document root) I just want... /home/thirdoct/public_html/test/ I just want the test directory, not the whole thing... Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/#findComment-378868 Share on other sites More sharing options...
Toshiba23 Posted October 26, 2007 Author Share Posted October 26, 2007 nevermind, did some php.net research: dirname($PHP_SELF) returns the directory after document root, so technically... require($_SERVER['DOCUMENT_ROOT'] . dirname($PHP_SELF) .'file.php'); would be the same thing as... require('file.php'); Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/#findComment-378871 Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 nevermind, did some php.net research: dirname($PHP_SELF) returns the directory after document root, so technically... require($_SERVER['DOCUMENT_ROOT'] . dirname($PHP_SELF) .'file.php'); would be the same thing as... require('file.php'); As long as you were working with a file in the directory. I would suggest making a constant in a common page define("SERVER_PATH", $_SERVER['DOCUMENT_ROOT']); also remember that $PHP_SELF means register_globals are on which is a security vulnerability. You should use $_SERVER['PHP_SELF'] instead. Quote Link to comment https://forums.phpfreaks.com/topic/74545-file-handling-location/#findComment-378875 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.