Frank Frank - 8 months ago 70
MySQL Question

Get blob image from MySQL by using Node as json and print it into PHP

I'm trying to make a basic image like this :

<img src='myImage' />

It's easy yeah ? But my image is stored as a blob in my MySQL BDD.

Already easy yeah ? the answer is here.

->Nope because I'm getting my SQL lines by Node sending it to my PHP as a JSON file. So the PHP will receive an array (The image is an array with a lot of numbers and the PHP's function named "base64_encode" need a String as paramater, and not an Array). I have to convert this array to an image to print it. But i don't find how to.

Anybody know ?

Image to explain here.

var_dump($myImg) ->

array(25890) { [0]=> int(137) [1]=> int(80) [2]=> int(78) [3]=> int(71) [4]=> int(13) [5]=> int(10) [6]=> int(26) [7]=> int(10) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(13) [12]=> int(73) [13]=> int(72) [14]=> int(68) [15]=> int(82) [16]=> int(0) [17]=> ...


Your array contains every single char as separate element as int. You must iterate by this array and convert it into char by chr function and concatenate in one string:

$string = '';
foreach ($yourArray as $el) {
  $string .= chr($el);

And now you can do with $string whatever you want, eg convert it with base64_encode