avatar_50x50という名前のフォルダーから画像をエコーしようとしています。ファイルの名前はusernameです。拡張子は常に画像ですが、ファイルの種類を特定するにはどうすればよいですか?
<img src="../images/users/avatar_50x50/<?php echo $sel_user['username']; ?>"
glob()
ユーザー名として名前を持つ画像が1つしかないことが確実な場合は、配列から最初の要素を使用して取得できます。
<?php
$file = glob('../images/users/avatar_50x50/'.$sel_user['username'].'.*');
echo '<img src="../images/users/avatar_50x50/'.$file[0].'" alt="" />';
?>
http://php.net/exif_imagetypeを使用
そして、「スイッチ」演算子を使用して正しい画像内線を見つけます。
$type = exif_imagetype($image);
switch($type) {
case IMAGETYPE_GIF:
$ext = '.gif';
// etc...
}