Topic: viewtopic.php : hidden warnings causing fatal error

Hello PunBB devs,

You may not accept this as a bug but I'm posting this for your consideration :

I'm running PunBB 1.2.15 on free web space provided by a French ISP called Free (free.fr). I have learned today that this particular provider's PHP installations are set to generate an E_FATAL error when the count of hidden E_WARNINGs goes over 30.

The following part of the viewtopic.php script (lines 211-216) generates a lot of hidden E_WARNINGs on our forum (a lot of our users have no avatars, or have a PNG image as an avatar) :

if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
    $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' alt="" />';
else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
    $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' alt="" />';
else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
    $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' alt="" />';

I have fixed this on my forum by testing in each case (gif, jpg, png) if the file exists :

$basename = $pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'];
if (file_exists($basename.'.gif') && $img_size = @getimagesize($basename.'.gif'))
    $user_avatar = '<img src="'.$basename.'.gif" '.$img_size[3].' alt="" />';
else if (file_exists($basename.'.jpg') && $img_size = @getimagesize($basename.'.jpg'))
    $user_avatar = '<img src="'.$basename.'.jpg" '.$img_size[3].' alt="" />';
else if (file_exists($basename.'.png') && $img_size = @getimagesize($basename.'.png'))
    $user_avatar = '<img src="'.$basename.'.png" '.$img_size[3].' alt="" />';

I realize that this problem is specific to my webspace provider, however, I think you should consider fixing it because :

- Other hosting providers may use similar settings,
- PunBB seems to be quite popular on Free.fr webpages : a Google search for "inurl:viewtopic.php site:free.fr punbb" returns 50800 results...

Cheers and keep up the good work ! smile

Re: viewtopic.php : hidden warnings causing fatal error

That's a very silly rule, but yes, using file_exists would probably be better.

Re: viewtopic.php : hidden warnings causing fatal error

I'll look into fixing this for 1.3, but you're right, it isn't really a bug.
Moved to PunBB Discussion

Re: viewtopic.php : hidden warnings causing fatal error

Fixed in changeset 1055
If there are any other instances of excessive warnings that you notice, feel free to post them.