Can’t understand how to get an image from the database. I know that it is better not to store the image in the database, but still, how to get it and output ??
& lt;? php
$ HostName = "LocalHost";
$ username = "root";
$ password = "x";
$ Database = "Photo_Test";
$ usertable = "photo";
// Pocillion to database
$ Conn = Mysqli_Connect ($ hostname, $ username, $ password, $ database) or DIE ('Oops');
$ SQL = "SELECT * from $ USERTABLE WHERE ID = 2";
Answer 1
Already there is an answer to your question.
Original:
https://stackoverflow.com/a/6273415
You can use several different methods depending on which PHP image library is installed. Here are some examples.
Please note that ECHO is just a trick that I use to display multiple images from the same PHP script when cyclically viewing the MYSQL result resource. You can also display through the header (), as shown @naveed.
Gd:
$ image = imagecreatefromstring ($ blob);
OB_START (); // You Could Also Just Output The $ Image Via Header () And Bypass This Buffer Capture.
imagejpeg ($ image, null, 80);
$ Data = OB_GET_CONTENTS ();
OB_END_CLEAN ();
Echo '& lt; img src = "data: image / jpg; base64,'. Base64_ENCode ($ Data). '" / & gt;';
ImageMagick (Imagick):
$ image = new imagick ();
$ image- & gt; readimageblob ($ blob);
Echo '& lt; img src = "data: image / png; base64,'. Base64_encode ($ image- & gt; getimageblob ()). '" / & gt;';
GraphicsMagick (Gmagick):
$ image = new gmagick ();
$ image- & gt; readimageblob ($ blob);
Echo '& lt; img src = "data: image / png; base64,'. Base64_encode ($ image- & gt; getimageblob ()). '" / & gt;';