简体   繁体   中英

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. 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

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;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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