I'm hoping someone here knows the answer to this. I wrote a script that uses
basename( __DIR__ )
then uses an if file exist function.
On my server this works fine, however on other sever it actually returns the word _DIR_
instead of the file path.
Did this change with a version of PHP or is there some other setting that makes it so this doesn’t work?
Lastly is there a better way to get the path of the file? Here is the whole line I’m using:
define('NIFTY_CONSTANT', trailingslashit (WP_PLUGIN_DIR . '/'. basename( __DIR__ ) ). '/lib/mdetect.php' );
(yes I know it's a WordPress function but this is not a WordPress question it's a PHP one)
__DIR__
is introduced in PHP 5.3 . Double check your PHP version .
Reference: http://php.net/manual/en/language.constants.predefined.php
If __DIR__
constant doesn't work on server A
, while works on server B
, then a PHP Version is an issue (As mentioned by @Shivan).
You can simply test it by calling phpinfo()
on both servers.
Here's a quick workaround for you:
// this should be at the top
if (!defined('__DIR__')) {
define('__DIR__', dirname(__FILE__));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With