4

私はこれに何時間も取り組んでいます。ネット上で見つかった解決策はほとんどありませんが、誰も私を助けてくれないようです。列タイプ bytea の Postgres DB から画像を取得する PHP を使用してブラウザに画像を表示する際に問題があります。私はここで何かが欠けていると確信しています。したがって、いくつかのガイダンスは本当にありがたいです。だから私は以下のコードを持っています:

$prod = new Product();
$prod->display_latest_product();
if( $prod->exists() ){
    $products = $prod->data();
    foreach($products as $product){
        echo $product->id;
        echo $product->binarydata;

        /* Solution below: I only get one image with broken link */
        header('Content-type: image/png');
        echo pg_unescape_bytea($product->binarydata);

        /* Solution below: I only get one image with broken link */
        header('Content-Type: image/png'); 
        $data=fgets($product->binarydata); 
        print(pack('H*',$data));

        /* bin2hex() expects parameter to be string but resource given */
        echo bin2hex($product->binarydata);

         /* Solution below: I only get one image with broken link */
        $image = stripcslashes($product->binarydata);
        header("Content-Type: image/png");
        print($image);
    }
}

調査と読書の後でまだ混乱しているので、これについての説明に感謝します。

4

2 に答える 2