HEZEKIAH
HEZEKIAH

Reputation: 9

Php images display from database

i created a form which store clients passports in my database. i want to retrive the images but its has not been giving me the images on the screen. instead , it write long alphabeth of different symbols .

below is my codes , pls help me out. thanks

    $sql = "SELECT * FROM `file` WHERE id = 8";
    $mq = mysqli_query($dbconnect, $sql) or die ("not working query");
    $row = mysqli_fetch_array($mq) or die("line 44 not working");
    $s=$row['data'];
    echo $row['data'];

   echo '<img src="'.$s.'" alt="HTML5 Icon"      style="width:128px;height:128px">';

what is wrong with my codes please.

thanks

Upvotes: 0

Views: 38

Answers (1)

n-dru
n-dru

Reputation: 9420

Because you say you see lots of characters instead of the filename, I assume that you don't store a path to that image (then you could use src as you tried to use), but the image content itself and that it is jpg (you can change to png or whatever type you have there). If so, use data URI syntax for src:

$src = "data:image/jpg;base64,".base64_encode($row['data']);
echo '<img src="'.$src.'" alt="HTML5 Icon" style="width:128px;height:128px">';

It is called data URI - you can read more about it for example here: https://en.wikipedia.org/wiki/Data_URI_scheme

Upvotes: 1

Related Questions