Using file_exists to check file in Uploads

You can’t use a file url in file_exists() like this:

file_exists( "http://example.com/wp-content/uploads/Example_Name_2_SM.jpg" );

You should rather use an absolute file path, for example:

file_exists( "/absolute/path/to/wp-content/uploads/Example_Name_2_SM.jpg" );

Then you should try

$meta = get_post_meta( $post->ID, '_meta_example_name', true );
$file = $upload_basedir . "https://wordpress.stackexchange.com/" . $meta . '_7_SM.jpg';
if ( file_exists( $file ) ) {
   //...
}

where

$upload_basedir = WP_CONTENT_DIR . '/uploads';

or

$upload_dir = wp_upload_dir();
$upload_basedir = $upload_dir['basedir'];

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)