简体   繁体   中英

How to display blob as image from oracle using PHP

I'm trying to display an image that is stored as a blob in oracle using PHP. I'm using the adodb library.

The code is as follows:

<?php
$db=conGenedesa();
    $query ="SELECT * FROM 'TABLE' p WHERE p.ID = $id";
    $result = odbc_exec($db, $query);

    $name;
    $dni;
    $jobID;
    $base;
    while(odbc_fetch_row($result)){
        $name = odbc_result($result, 'PER_APELLIDO_PATERNO') . ' ' . odbc_result($result, 'PER_APELLIDO_MATERNO') . ' ' . odbc_result($result, 'PER_NOMBRES');
        $dni = $rut . '-' . odbc_result($result, 'PER_RUT_DV');
        $jobID = odbc_result($result, 'PER_CAR_CODIGO');
        $base = odbc_result($result, 'PER_MOVIL_IMG');
    }

    $src;
    if($base == null){
        echo 'null';
    }
    else{
        $src='data:image/jpeg;base64,'.base64_encode($base);
    }
?>
<img src="<?php echo $src; ?>" />

I know the image is not corrupted, because i can see it from another application using dotnet.

UPDATE:

In the end, PHP was truncating the blobs output. I corrected it inserting this line.

ini_set('odbc.defaultlrl', '10M');

Although it's for OCI8 not ADOdb, the section "Uploading and Displaying an Image" on page 236 of The Underground PHP and Oracle Manual may have some helpful clues.

Since you seem to have fetched your data OK, your question isn't really an Oracle one, so plenty of other resource can be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM