adredz Posted November 21, 2009 Share Posted November 21, 2009 I have started studying PHP...pls explain to me...thanks Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/ Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 The function dirname simply returns the directory from a full path, so for example c:\something\something\file.php would return c:\something\something\. _FILE_ is a magic constant that simply returns the path of the current file. The second bit, dirname(ABSPATH), appears to use a user defined constant 'ABSPATH' (to my knowledge it's not a generic PHP one), it would probably require a line of code along the lines of define('ABSPATH', __FILE__);. Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962518 Share on other sites More sharing options...
Mcfarlin Posted November 21, 2009 Share Posted November 21, 2009 yes define(’ABSPATH’, dirname(__FILE__).’/'); could be used where ABSPATH would get you the absolute path to the file location within your directory The __FILE__ returns the full path and filename of the file accomplished by dirname() which returns directory name component of path. i have been up for a few to many hours tho so not at 100% here. lol Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962520 Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 i have been up for a few to many hours tho so not at 100% here. lol I guess it's lucky I already answered then really isn't it. Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962524 Share on other sites More sharing options...
adredz Posted November 21, 2009 Author Share Posted November 21, 2009 yes define(’ABSPATH’, dirname(__FILE__).’/'); could be used where ABSPATH would get you the absolute path to the file location within your directory The __FILE__ returns the full path and filename of the file accomplished by dirname() which returns directory name component of path. i have been up for a few to many hours tho so not at 100% here. lol I am sorry I am a bit confused. So if this line of code "define(’ABSPATH’, dirname(__FILE__).’/');" is under something.php, does it mean the _FILE_ pertains to something.php? And does the .'/' pertains to current directory? Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962547 Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 Yes __FILE__ will be the path of something.php, take into account that if you use it in a script that is include'd in another script it will return the filename of the file the line is written in not the file that included it. './' in html would mean up one directory and should be before a path, I have no idea why Mcfarlin used it there. Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962549 Share on other sites More sharing options...
adredz Posted November 21, 2009 Author Share Posted November 21, 2009 './' in html would mean up one directory and should be before a path, I have no idea why Mcfarlin used it there. I am actually trying to absorb the wordpress source code and learn php from it. =) Under the file wp-load.php is this line: define( 'ABSPATH', dirname(__FILE__) . '/' ); What could .'/' mean? Though here's another line which makes sense to me: ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) Here, wp-config.php is on the same dir as wp-load.php. Given the ABSPATH is c:/something/something, putting it as a parameter of dirname() makes it c:/something now right? And you said .'/' is up one directory, so file_exists() is actually looking into the right path... So could it be that define( 'ABSPATH', dirname(__FILE__) . '/' ); is incorrect syntax wise? Please correct me if I am wrong. I have a feeling my assumption here is entirely wrong! =) Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962564 Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 Oh sorry my bad, the font seems a bit smaller since the last update I thought it was './' not just a slash. I think in my first post I listed the output of dirname having a trailing slash, which it doesn't. In my first example the output should have been 'c:\something\something'. All that code does is stores the directory that the file is contianed in (complete with trialing slash), into a constant called ABSPATH. The dot between dirname() and the '/' simply means concatinate that slash on the end of the path returned. Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962571 Share on other sites More sharing options...
adredz Posted November 21, 2009 Author Share Posted November 21, 2009 Thanks. It's clearer now. ONe last question. What's the difference between ( file_exists( ABSPATH . 'wp-config.php') ) and ( file_exists( dirname(ABSPATH) . '/wp-config.php' )? Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962579 Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 There isn't one. But I have to say I don't see the point of the second example. Why use dirname to get a path concatinate '/' to the end of it and store it in ABSPATH only to then call dirname on it again and add the forward slash in the second part. Basically you have redundant code. Link to comment https://forums.phpfreaks.com/topic/182402-what-do-dirname_file_-and-dirnameabspath-mean/#findComment-962583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.