グロブを使用すると、ファイル拡張子を含むファイルの完全なパスが既に存在します。最初に表示するには
-
$result = glob('uploads/logo_'.$row['id'].'.*');
if(!empty($result))
{
foreach ($result as $file) {
if (@is_array(getimagesize($file))) {
$relativePath = end(explode('/', $file));
echo '<p><img src="uploads/' . $relativePath . '" height="75"></p>';
}
}
}
:すべての一致した画像を表示するには
:私はその場で、ここでいくつかのコードを(私はまだそれをテストしていない)書かれている
一致するイメージ:
$result = glob('uploads/logo_'.$row['id'].'.*');
if(!empty($result))
{
$file = current($result);
if (@is_array(getimagesize($file))) {
$relativePath = end(explode('/', $file));
echo '<p><img src="uploads/' . $relativePath . '" height="75"></p>';
}
}
私は画像ファイルを除外しています。画像ファイル以外のファイルがないと確信できる場合は、@is_array(getimagesize($file))
の条件をスキップしてください。