0

I have to show an image which is stored in Oracle database as OCI-Lob Object.

I have used following code:

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(); 

I have found above code with some research on Google. But those seems to be not working. What should I do to extract image stored in Oracle Database through PHP.

Thanks in advance.

Sergey Tsibel
  • 1,595
  • 1
  • 18
  • 31
Blue Rose
  • 523
  • 1
  • 3
  • 14
  • What does "not working" mean? Are you getting errors? What's the exact output? – Mat Mar 09 '14 at 07:48
  • This might be helpful http://stackoverflow.com/questions/3056287/oracle-blob-as-img-src-in-php-page – Sergey Tsibel Mar 09 '14 at 07:51
  • @Mat There are no errors. It displays null. Nothing change. – Blue Rose Mar 09 '14 at 08:39
  • @castt : I did went through that post and tried everything that has explained there but it gives "The webpage not found error". I just don't understand why its not working?? Can anyone please help. Please please............ – Blue Rose Mar 09 '14 at 08:47

2 Answers2

2

Actually my problem has been solved. I am posting here the solution so that anyone else facing same problem would take benefit from it.

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

I hope it would help someone, someday. BTW thanks everyone for commenting. :)

Blue Rose
  • 523
  • 1
  • 3
  • 14
0

Since you are using OCI_RETURN_LOBS, you should already have the BLOB in $a at line 3. You are not fetching the returned array, try this code:

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;
Mikpa
  • 1,912
  • 15
  • 20
  • Its giving error as "The image cannot be displayed because it contains error". But the image is fine in db. – Blue Rose Mar 09 '14 at 08:53
  • please look at the value printed from $a without using your image headers – Mikpa Mar 09 '14 at 08:55
  • `if(oci_fetch_array($rssqlclass,OCI_ASSOC | OCI_RETURN_LOBS)) { $a=oci_result($rssqlclass,"photo"); } header("Content-type: image/jpeg");print $a;` – Blue Rose Mar 09 '14 at 09:05
  • yes, but try removing the header() just to check what really is in $a. Comment out header() add print_r($a) – Mikpa Mar 09 '14 at 09:49
  • which one?? I have already tested above code as mentioned and its not working?? – Blue Rose Mar 10 '14 at 11:10