Q:

PHP - Set default picture for users

I'm creating a profile-system including a profile picture. I want to have a default picture if the user hasn't uploaded a picture. To look what picture fits the user, I use their user_id. But how do I put a default picture?
My current code is;
<image src="img/upload/groot/'. $user_id .'.jpg" height="120px" width="120px" /><br/><br />';

A:

Use file_exists() to check if the image exists, if it does, show it, if not, show a default image:
$userImage = 'img/upload/groot/' . $user_id . '.jpg';
$defaultImage = 'path/to/default/img';

$image = (file_exists($userImage)) ? $userImage : $defaultImage;

Then use $image as your image src:
<img src="<?php echo $image; ?>" />

