Reputation: 87
I'm trying to echo an image from a folder called avatar_50x50, with the name of the file being the username. Although the extension will always be an image, how will I determine what file type it is?
<img src="../images/users/avatar_50x50/<?php echo $sel_user['username']; ?>"
Upvotes: 0
Views: 687
Reputation: 618
Use http://php.net/exif_imagetype
And than use "switch" operator to find right image ext.
$type = exif_imagetype($image);
switch($type) {
case IMAGETYPE_GIF:
$ext = '.gif';
// etc...
}
Upvotes: 0
Reputation: 39704
you can use glob()
and take first element from array if you are sure there is only one image with name as username:
<?php
$file = glob('../images/users/avatar_50x50/'.$sel_user['username'].'.*');
echo '<img src="../images/users/avatar_50x50/'.$file[0].'" alt="" />';
?>
Upvotes: 1