dqu92800
2016-06-13 09:29 阅读 76

通过使用Node作为json从MySQL获取blob图像并将其打印到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]=> ...
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanli0687 duanli0687 2016-06-13 09:59

    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

    点赞 评论 复制链接分享

相关推荐