有谁知道如何存储在数据库中的二进制数据转换回的图像? [英] Does anyone know how to convert binary data stored into a database back into an image?
本文介绍了有谁知道如何存储在数据库中的二进制数据转换回的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个数据库已存储的图像作为二进制文件。我期待将其转换回为JPEG在PHP。有谁知道这可能是实现呢?
A database has stored an image as binary. I'm looking to convert it back to a JPEG in PHP. Does anyone know how this might be accomplished?
我知道这可能是东西,我可以通过谷歌找到,但我还没有追查一个答案,并认为这将是最好的对冲投注我在这里提一个问题。
I'm aware this might be something that I can find through Google but I have not yet tracked down an answer and thought it would be best to hedge my bets and ask a question here.
如果我发现之前,我得到回应,我将在这里发布的解决方案。
If I find out before I get a response, I will post the solution here.
推荐答案
只需从数据库中的数据,并把它放在变量$ image_data_from_database
Simply select the data from the database and put it in the variable $image_data_from_database
保存到文件:
<?php
file_put_contents("image.jpg", $image_data_from_database);
?>
或显示图像就地:
<?php
header('Content-Type: image/jpeg');
echo $image_data_from_database;
?>
这篇关于有谁知道如何存储在数据库中的二进制数据转换回的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文