我在这个问题上卡了好几个小时。在网上找到了一些解决方案,但似乎没有一个能帮助我。我使用PHP从Postgres数据库中获取类型为bytea的列中的图像,在浏览器上显示图像时出现了问题。我确定我在这里漏掉了一些东西。所以非常感谢任何指导。下面是我的代码:
$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);
}
}
我希望您能给我一些解释,因为我在研究和阅读后仍然感到困惑。