Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to check if a file exist in my plugin dir:

if (fileexists) {
...
}
else
{
...
}

However, if in place of fileexists I use file_exists(WP_PLUGIN_DIR . "/myplugin/myfile.ext") it returns always true, whereas if I use file_exists(plugins_url( "myfile.ext", __FILE__ )) it returns always false, irrespective of the argument I use is a file that exists or not.

I do not know if it is relevant to specify that I'm working in a locale environment. WP_PLUGIN_DIR returns C:\Users\MyName\Documents\webserver\www\wordpress/wp-content/plugins/myplugin/myfile.ext (and I see some slashes and some backslashes).

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Use

if( file_exists(plugin_dir_path(__FILE__) . 'myfile.ext') ) {}

instead of

if( file_exists( plugins_url( "myfile.ext", __FILE__ ) ) ) {}

See plugin_dir_path in the Codex.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.