Grasper
Grasper

Reputation: 1313

PHP WordPress file_exists not working

I'm working on a plugin and trying to embed something if the file/folder exists. This perfectly works in php but not within WP. Any help would be appreciated. This code is in the admin area under the plugin's setting page. And yes, I'm sure the path to the folder is correct.

$filename = plugins_url('../admin_side/webmailing/install/', __FILE__);

if (file_exists($filename)) { 

echo 'something';

 else {

echo 'something else';

} 

Upvotes: 0

Views: 1684

Answers (1)

Nathan Dawson
Nathan Dawson

Reputation: 19308

file_exists expects a file path but you're passing it a URL.

Change:

$filename = plugins_url('../admin_side/webmailing/install/', __FILE__);

To:

$filename = plugin_dir_path( __FILE__ ) . 'admin_side/webmailing/install/';

Upvotes: 2

Related Questions