If I understand the issue, you want to reference a file, you will know the filename, but the extension could be one of a few possibilities. Rather than getting a list of every file, I would be inclined to do it the other way and check the list of extensions. This will presumably be a much shorter list:
<?php
$exts = array('png', 'gif', 'jpg', 'jpeg');
$file = 'images/hello';
$src = '';
foreach ($exts as $ext) {
if (file_exists("$file.$ext")) {
$src = "$file.$ext";
break;
}
}
printf('<img src="%s" />', $src);
?>