Search code examples
phpfile-exists

file_exists() showing opposite results than expected


I have a very, very simple function:

function getUserImage($id) {

    if (file_exists(SITE_ROOT . '/images/' . $id)) {
        return "http://www.---.net/images/" . $id;                         
    } else {
        return "http://www.---.net/images/usericon.png";  
    }
}

It is being called this way:

<img src="<?php echo getUserImage($row['user_id'].".jpg"); ?>" />

What I am trying to do is show a default icon if the user does not have a profile picture. It is showing the default icon every time even though the correct path is being tested (I have confirmed this). Maybe I am using file_exists() wrong?


Solution

  • function getUserImage($id) {
    
        if (file_exists(SITE_ROOT . '/profile_pics/' . $id)) {
            return "http://www.---.net/profile_pics/" . $id;                         
        } else {
            return "http://www.---.net/images/usericon.png";  
        }
    
    
    }
    

    I was searching in the wrong folder. It should have been profile_pics all along~