0

I'm currently experiencing a weird problem while I converted a web application to ODBC using PostgreSQL (coming from MySQL with PHP mysqli-connector).

I noticed that images that are stored as a bytea in PostgreSQL database and thrown into PHP's base64 function are not shown correctly. At some point it's cut off after a couple of lines. This cut off is with all bytea image data that is stored in our database, we have that for logos and signatures.

If you inspect the img tag with the browser's inspector you'll see (at least in Chrome) that there is a lot data of that image missing.

What I do is a SELECT * FROM table and then in a for-loop encode the image as base64:

$clients[$i]['logo'] = base64_encode($clients[$i]['image']);

$clients[$i]['image'] = this is the bytea in the database and

$clients[$i]['logo'] = this is the base64 String that I display in a Smarty template like this: data:image/png;base64,{$client.logo}

I hope you can help.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • Can you show us some relevant PHP code please. For instance: the code where you're inserting the value into the `bytea` field; the code where you're retrieving the value and placing it into `$clients[$i]['image']`. Also, have you checked the notes on this PHP manual page? http://php.net/manual/en/function.pg-escape-bytea.php – IMSoP May 03 '16 at 15:28
  • Untagging [tag:smarty] and tagging [tag:postgresql] instead, since this seems to be much more about the database interaction than the template logic. – IMSoP May 03 '16 at 15:29
  • Thanks. I'm not writing into the database because it is a monitoring-tool. The other side is being developed by another company. But I recently found a solution: php.ini settings -> odbc.defaultlrl = 65536 was set to about 4xxx. – Matt Rothtauscher May 04 '16 at 05:46
  • Glad you found a solution. You should [add it as an Answer to your own Question](http://stackoverflow.com/help/self-answer), so that other people finding this question in future can benefit. :) – IMSoP May 04 '16 at 08:52

1 Answers1

0

The solution is the length of data in the odbc.ini files. If the length is limited, base64 strings that are too long will be cut off. Just needed to increase the size.