I figure if I execute file_exists for a single file type (GIF) versus executing it three times (GIF, JPG, PNG) it'll definitely create less load then a MySQL query. I could restrict avatar file types or simply convert them to GIF format...not sure.
As I'm only just starting to program my very first generation of PHP/MySQL based membership script (sort of a test version if you will) I'm not sure how often this will occur; I'm not sure if I will need to call a query independently if there is no other data I need to fetch from the MySQL database. I'm thinking there isn't though I could be wrong.
So worst case scenario is I think I'll always fetch more then one column/row and thus should stick the file extension in the database (only three letters for the extension itself). I'd really like to take this sort of thing in to consideration now to get in to good coding practices as I learn more. Thoughts?
Code: Select all
$image_avatar_gif = 'upload/'.get_id_length($row['id']).'_'.$row['username'].'_avatar.gif';
$image_avatar_jpg = 'upload/'.get_id_length($row['id']).'_'.$row['username'].'_avatar.jpg';
$image_avatar_png = 'upload/'.get_id_length($row['id']).'_'.$row['username'].'_avatar.png';
if (file_exists($image_avatar_gif)) {echo '<img class="left margin" src="'.$image_avatar_gif.'" />';}
else if (file_exists($image_avatar_jpg)) {echo '<img class="left margin" src="'.$image_avatar_jpg.'" />';}
else if (file_exists($image_avatar_png)) {echo '<img class="left margin" src="'.$image_avatar_png.'" />';}