One bug I fixed this week was down to one of the features of file_exists() function. File_exists(string $filename ) will return true if the filename points to a file or directory. Is_file( string $filename ) will return false if the given path is a directory. To check whether filename is actually a file, use is_file().
For both, $filename cannot be a relative path, so I always use document root to ensure an absolute path.
if( file_exists( $_SERVER{'DOCUMENT_ROOT'} . "/images/picture.jpg")) {
...
}
?>

