file get contents - Assign Image SRC in php
984
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 toecho
it, I want to assign it assrc
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.
Answer
Solution:
Inside the HTML you still need to
echo
the value of$src
. This should work:Answer
Solution:
Try with PHP tags like below:-
Answer
Solution:
Reasonable solution I can think of is
but the code where you get the image source has to be above the image tag, so you have the
$src
.Answer
Solution:
You are using PHP language and in Php, you can't pass variable directly in the Tag you have to set a variable in the PHP environment. To create Php environment you can right
<?php ?>
or you can use to echo variable<?= ?>
between these PHP tags you can pas your variables to echo and assign or anything else what you want to do.