Oracle Blob作为PHP页面中的img src [英] Oracle Blob as img src in PHP page

查看:110
本文介绍了Oracle Blob作为PHP页面中的img src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a site that currently uses images on a file server. The images appear on a page where the user can drag and drop each as is needed. This is done with jQuery and the images are enclosed in a list. Each image is pretty standard:

<img src='//network_path/image.png' height='80px'>

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

Now however I need to reference images stored as a BLOB in an Oracle database (no choice on this, so not a merit discussion). I have no problem retrieving the BLOB and displaying on it's own using:

$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;

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

But I need to [efficiently] get that image as the src attribute of the img tag. I tried imagecreatefromstring() but that just returns the image in the browser, ignoring the other html. I looked at data uri, but the IE8 size limit rules that out.

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

So now I am kind of stuck. My searches keep coming up with using a src attribute that loads another page that contains the image. But I need the image itself to actually show on the page. (Note: I say image, meaning at least one image but as many as eight on a page).

任何帮助将不胜感激。

推荐答案

嗯,你可以做一些事情。你可以制作一个会呈现图像的页面

Well, you can do a few things. You can either make a page that will render the image

<img src="image.php?id=123" />

该image.php页面将包含:

That image.php page would have this:

$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;
}

或者,您可以将base64编码到src中(注意,并非所有浏览器处理好这个):

Or, you could base64 encode it into the src (note, not all browsers handle this well):

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

这篇关于Oracle Blob作为PHP页面中的img src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆