0

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

1
  • Please don't put your die() messages onto a production server. Commented Jan 11, 2016 at 16:57

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

k. i do I stored the image in a path. i think you mean that should happen in the form where the image was collected from right?
no, I mean to show it. So if your $row['data'] is a path, how is that possible you see those characters? I still guess you store it as image contents - try to ise this code as in my answer, but use proper extension - png, jpg...
yea , i stored it as image content. its from a file upload html form. also , the code worked . i m very greatful. but please explain those methoed you used . i meant the function of the . base64_encode. thks alot
Great! There is plenty of info about data URI in the web. The bad part is it cannot be stored in browser cache as image file, but good part is it saves one request. BTW, if you like the answer, please accept it.
@HEZEKIAH Please accept the answer as you've mentioned it has solved your issue. This will let others know that you don't need any more help with this and people will know what worked.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.