[英]Does anyone know how to convert binary data stored into a database back into an image?
A database has stored an image as binary. 数据库已将图像存储为二进制。 I'm looking to convert it back to a JPEG in PHP.
我希望将它转换回PHP格式的JPEG。 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. 如果我在收到回复之前发现了,我会在这里发布解决方案。
Simply select the data from the database and put it in the variable $image_data_from_database 只需从数据库中选择数据并将其放入变量$ image_data_from_database中
Save to file: 保存到文件:
<?php
file_put_contents("image.jpg", $image_data_from_database);
?>
or display the image in-place: 或就地显示图像:
<?php
header('Content-Type: image/jpeg');
echo $image_data_from_database;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.