After retrieve image path from database I want to pass it to <img>
tag to show up,
I read this solution, but I do not want to echo
it, I want to assign it as src
for image tag
I tried this:
$image = mysqli_fetch_array($user_images);
$img1 = $image['file_path'];
$imageData = base64_encode(file_get_contents($img1));
$src = 'data: '.mime_content_type($img1).';base64,'.$imageData;
How can I assign $src to image, I tried this but no luck :(
<img id="img1" width="150" height="150" src="' . $src . '"/>
Thanks in advance.
Inside the HTML you still need to echo
the value of $src
. This should work:
<img id="img1" width="150" height="150" src="<?php echo $src; ?>"/>