【问题标题】:Get blob image from MySQL by using Node as json and print it into PHP使用 Node 作为 json 从 MySQL 获取 blob 图像并将其打印到 PHP
【发布时间】:2016-06-13 09:29:48
【问题描述】:

我正在尝试制作这样的基本图像:

<img src='myImage' />

很简单吧?但是我的图像在我的 MySQL BDD 中存储为一个 blob。
已经很容易了吧?答案是here
-> 不,因为我通过 Node 获取我的 SQL 行,将其作为 JSON 文件发送到我的 PHP。所以 PHP 将接收一个数组(图像是一个包含很多数字的数组,并且名为“base64_encode”的 PHP 函数需要一个字符串作为参数,而不是一个数组)。我必须将此数组转换为图像才能打印。但我不知道怎么做。

有人知道吗?

图片解释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]=> ...

【问题讨论】:

    标签: php mysql json node.js


    【解决方案1】:

    您的数组包含每个单独的字符作为 int 的元素。您必须通过此数组进行迭代,并通过chr 函数将其转换为 char 并连接到一个字符串中:

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

    现在你可以用$string做任何你想做的事情,例如用base64_encode转换它

    【讨论】:

      猜你喜欢
      • 2013-12-20
      • 2018-11-01
      • 2010-10-23
      • 2011-06-13
      • 1970-01-01
      • 2013-03-05
      • 2020-10-10
      • 2018-01-14
      • 1970-01-01
      相关资源
      最近更新 更多