Oracle Blob作为PHP页面中的img src

men*_*kes 5 php oracle blob image

我有一个网站,目前使用文件服务器上的图像.图像显示在用户可以根据需要拖放的页面上.这是通过jQuery完成的,图像包含在列表中.每张图片都很标准:

<img src='//network_path/image.png' height='80px'>
Run Code Online (Sandbox Code Playgroud)

但是现在我需要在Oracle数据库中引用存储为BLOB的图像(没有选择,所以不是优点讨论).我没有问题检索BLOB并使用以下方式显示它自己:

$sql = "SELECT image FROM images WHERE image_id = 123";
$stid = oci_parse($conn, $sql);
oci_execute($stid);
$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
$img = $row['IMAGE']->load();
header("Content-type: image/jpeg");
print $img;
Run Code Online (Sandbox Code Playgroud)

但我需要[有效]将该图像作为img标记的src属性.我尝试了imagecreatefromstring(),但只是在浏览器中返回图像,忽略了其他的html.我查看了数据uri,但IE8大小限制规定了.

所以现在我有点卡住了.我的搜索不断使用src属性来加载包含图像的另一个页面.但我需要将图像本身显示在页面上.(注意:我说图像,意思是至少一个图像,但在页面上多达八个).

任何帮助将不胜感激.

irc*_*ell 7

好吧,你可以做一些事情.您可以创建一个将呈现图像的页面

<img src="image.php?id=123" />
Run Code Online (Sandbox Code Playgroud)

那个image.php页面会有这个:

$sql = "SELECT image FROM images WHERE image_id = " . (int) $_GET['id'];
$stid = oci_parse($conn, $sql);
oci_execute($stid);
$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
if (!$row) {
    header('Status: 404 Not Found');
} else {
    $img = $row['IMAGE']->load();
    header("Content-type: image/jpeg");
    print $img;
}
Run Code Online (Sandbox Code Playgroud)

或者,你可以将它6464编码到src中(注意,并非所有浏览器都能很好地处理这个):

<img src="data:image/jpeg;base64,<?php echo base64_encode($img); ?>" />
Run Code Online (Sandbox Code Playgroud)