Jump to content

Archived

This topic is now archived and is closed to further replies.

adredz

what do dirname(_FILE_) and dirname(ABSPATH) mean?

Recommended Posts

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__);.

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

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.  ;)

Share this post


Link to post
Share on other sites

 

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? 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

'./' 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! =)

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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' )?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.