保存された画像「bytea」タイプのpostgresデータベースがあり、PHPを使用してブラウザーに表示しようとしています。そのうちの 1 つを表示する方法を見つけましたが、複数表示することはできません。私が使用するコードは次のとおりです。
ファイル名 - display_image.php
$conn = pg_connect("dbname=test user=postgres password=postgres");
$temp = '/home/postgres/tmp.jpg';
$query = "select lo_export(image, '$temp') from map ";
$result = pg_query($query);
if($result)
{
while ($line = pg_fetch_array($result))
{
$ctobj = $line["image"];
echo "<IMG SRC=show.php> </br>";
}
}
else { echo "File does not exists."; }
pg_close($conn);
ファイル名 - show.php
header("Content-type: image/jpeg");
$jpeg = fopen("/home/postgres/tmp.jpg","r");
$image = fread($jpeg,filesize("/home/postgres/tmp.jpg"));
echo $image;
問題は、1 つの画像のみを表示する「tmp.jpg」仮想ファイルにあるようです。クエリの結果が 7 つの画像の場合、while ループ内で同じ画像が 7 回表示されます。どうすればこれを解決できますか? 関心をお寄せいただきありがとうございます。