Syntax problem when checking for a file

Posted by Luke on Stack Overflow See other posts from Stack Overflow or by Luke
Published on 2010-12-31T00:48:30Z Indexed on 2010/12/31 0:53 UTC
Read the original article Hit count: 132

Filed under:

This piece of code has previously worked but I have C&P it to a new place and for some reason, it now won't work!

        <?
        $user_image = '/images/users/' . $_SESSION['id'] . 'a.jpg';
        if (file_exists(realpath(dirname(__FILE__) . $user_image))) 
        {
            echo '<img src="'.$user_image.'" alt="" />';
        } 
        else 
        {
            echo '<img src="/images/users/small.jpg" alt="" />';
        }
        ?>

As you can see, I am checking for a file, if exists, showing it, if not, showing a placeholder.

The $_SESSION['id'] variable does exist and is being used elsewhere within the script.

Any ideas what the problem is?

Thanks

© Stack Overflow or respective owner

Related posts about php