How do I save an image in a path by searching from an Oracle base?

Asked

Viewed 100 times

2

I’m trying with the PHP GD library, like this:

<?php
$con = oci_connect('root', '123', '172.16.1.100/DB');
$stmt = oci_parse($con, "SELECT Nome, Imagem FROM Tabela where ID = '1'");
oci_execute($stmt);

$row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS);
if (!$row) {
    header('Status: 404 Not Found');
} else {
    $assinatura = $row['IMAGEM'];
    header("Content-type: image/png");
    $imagem = imagecreatefrompng($assinatura);
    imagepng($imagem,"img-".$row['NOME'].".png");
    imagedestroy($imagem);
}
?>

But not saved. If I give a print $signature it appears the picture straight.

  • It shouldn’t be that, but try without the imagedestroy($imagem);.

  • It didn’t work either @Andreicoelho

  • What comes from the bank is already the contents of the file? Don’t you do any manipulation? If yes, then you don’t need the GD library, you can directly save the binary file using file_put_contents for example.

  • It comes in several special characters @Júlioneto, if only to pick up the Base and show me up with you. However, I would like to take the image of the Oracle Base and save it in one location only to save the path of it in another Base.

  • It is strange that this code does not work. Mainly because you managed to print the image... With the var_dump(imagepng($imagem,"img-".$row['NOME'].".png")); returns what?

  • I misread the statement when I give print $assinatura it shows the image instead of the $imagem.. the var_dump() returned null in $imagem and in $assinatura retorna '�PNG&#xA;&#xA;���&#xA;IHDR�������:���_��0���IDATx��GoA��/wD�b2�"��E'rGD�Y؀9�Ӊ�A�F_K�j�ݳ;����[%Y������ͫW�=n7�>' e isso continua.. @Andreicoelho

  • This removing the header("Content-type: image/png") not to try to print some image.

Show 2 more comments

1 answer

1


I managed to solve it, not the way I wanted, but it worked!

First I converted the special characters with base64_encode($assinatura) and entered it into the other Database (Mysql). Then I recovered this data with

print base64_decode($assinatura); 
header("Content-type: image/png");

In case anyone has another solution..

  • cool! Still it’s good to "investigate" the reason it didn’t work out.

  • 1

    From what I saw @Andreicoelho, the imageCreateFromPng() expects a location where the image is (a file or URL) and returns null in case of error. Reference

Browser other questions tagged

You are not signed in. Login or sign up in order to post.