【问题标题】:Retrieve image stored in Oracle database as lob through PHP通过PHP检索存储在Oracle数据库中的图像作为lob
【发布时间】:2014-03-09 07:46:34
【问题描述】:

我必须将存储在Oracle 数据库中的图像显示为OCI-Lob 对象。

我使用了以下代码:

if(oci_fetch_array($rssqlclass,OCI_ASSOC | OCI_RETURN_LOBS)) {
  $a = oci_result($rssqlclass,"image");
}
header('Content-type: application/octet-stream;');
header('Content-disposition: attachment;filename='.$_GET['name']);

print $a->load(); 

我通过对 Google 的一些研究找到了上述代码。但这些似乎不起作用。通过PHP提取存储在Oracle数据库中的图像应该怎么做。

提前致谢。

【问题讨论】:

  • “不工作”是什么意思?你有错误吗?确切的输出是什么?
  • 这可能会有所帮助stackoverflow.com/questions/3056287/…
  • @Mat 没有错误。它显示为空。没有任何变化。
  • @castt :我确实浏览了该帖子并尝试了那里解释的所有内容,但它给出了“找不到网页错误”。我只是不明白为什么它不起作用?任何人都可以请帮忙。请……请……

标签: php image oracle image-processing lob


【解决方案1】:

其实我的问题已经解决了。我在这里发布解决方案,以便其他面临相同问题的人从中受益。

$sql="select photo from tblphoto where id='$id'  ";
$query= oci_parse($connect, $sql);
oci_execute($query); 
$showrow = oci_fetch_row($query);
if(!$showrow){
return;
}else{
$image=$showrow['0']->load();
header("Content-type: image/JPEG");
print $image;
}

我希望有一天它会对某人有所帮助。顺便说一句,感谢大家的评论。 :)

【讨论】:

    【解决方案2】:

    由于您使用的是 OCI_RETURN_LOBS,因此您应该已经在第 3 行的 $a 中有 BLOB。您没有获取返回的数组,请尝试以下代码:

    if($res = oci_fetch_array($rssqlclass,OCI_ASSOC | OCI_RETURN_LOBS)) {
      $a = $res['image'];
    }
    header('Content-type: application/octet-stream;');
    header('Content-disposition: attachment;filename='.$_GET['name']);
    
    print $a;
    

    【讨论】:

    • 它给出的错误是“图像无法显示,因为它包含错误”。但图像在数据库中很好。
    • 请查看从 $a 打印的值,不要使用您的图像标题
    • if(oci_fetch_array($rssqlclass,OCI_ASSOC | OCI_RETURN_LOBS)) { $a=oci_result($rssqlclass,"photo"); } header("Content-type: image/jpeg");print $a;
    • 是的,但尝试删除 header() 只是为了检查 $a 中的真实内容。注释掉 header() 添加 print_r($a)
    • 哪一个??我已经测试过上面提到的代码并且它不起作用??
    猜你喜欢
    • 2018-10-10
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    相关资源
    最近更新 更多