Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I display image from mysql PHP

Tags:

php

mysql

Please help. Im trying to display the image of each user using their student ID BUT it displays unknown characters as image on my page as below

%�S$P��H�~Q��-�}Y>ZTW�)�,G����g�~)�1WN�{�,��!���^j-����9�4���K�����

$sql_up="SELECT content FROM sp_uploads WHERE s_id= 'RC49557'";
$result_set=mysql_query($sql_up);

while($row_up = mysql_fetch_array($result_set))
 {
    $pp = $row_up['content'];
 } 

    echo "<td>  
 <img style=\"float:right; margin:5px; width:150px; height:150px; padding:10px; \" 
 src=\"  data:image/jpg;charset=utf8;base64,<?php echo $pp ?>   \"  /> </td>"; 
like image 760
4Jean Avatar asked Oct 18 '22 19:10

4Jean


1 Answers

This will do. You don't need to open PHP tags inside PHP tags.

$sql_up="SELECT content FROM sp_uploads WHERE s_id= 'RC49557'";
$result_set=mysql_query($sql_up);

while($row_up = mysql_fetch_array($result_set))
 {
    $pp = $row_up['content'];
 } 

 echo "<td>  
 <img style='float:right; margin:5px; width:150px; height:150px; padding:10px;' 
 src='data:image/jpg;charset=utf8;base64, $pp' /> </td>"; 

I'm assuming the img data is correct.

like image 146
Phiter Avatar answered Nov 01 '22 11:11

Phiter