[Solved] Retrieve image long raw datatype stored in oracle database in php


I’m using this same functionality in one of my project, please check my code below

you can either make a page that will render the image

<img src="https://stackoverflow.com/questions/50098121/image.php?id=123" />

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

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); ?>" />

7

solved Retrieve image long raw datatype stored in oracle database in php