Raj
Raj

Reputation: 3061

Function to get currently executing directory name of executing file

How to get the currently executing directory of the currently executing file? This needs to return the currently executing file's directory even if the file is included by another file. I landed on this:

$dir =  str_replace(basename(__FILE__),"",__FILE__);

But is there a more straightforward way?

Upvotes: 0

Views: 128

Answers (1)

EmeraldCoder
EmeraldCoder

Reputation: 547

To get the directory of the file I use the dirname function like this :

$dir = dirname(__FILE__);

Upvotes: 4

Related Questions