简体   繁体   English

通过使用Node作为json从MySQL获取blob图像并将其打印到PHP中

[英]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. 但是我的图像作为Blob存储在我的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. ->否,因为我通过Node将SQL行作为JSON文件发送到PHP来获取SQL行。 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). 因此,PHP将收到一个数组(图像是一个具有很多数字的数组,而名为“ base64_encode”的PHP函数需要使用String作为参数,而不是数组)。 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) -> 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. 您的数组包含每个单个char作为int的单独元素。 You must iterate by this array and convert it into char by chr function and concatenate in one string: 您必须通过此数组进行迭代,并通过chr函数将其转换为char并连接在一个字符串中:

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

And now you can do with $string whatever you want, eg convert it with base64_encode 现在,您可以使用$string任何操作,例如,使用base64_encode转换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM