Jump to content

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


adredz

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

Link to comment
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

Link to comment
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? 

Link to comment
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.

Link to comment
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! =)

 

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.