it seems like I cannot style my echoed image in php. How can I do this? Thanks :)
<img src="data:image/jpeg;base64,'.base64_encode($row['image'] ).'" height="80px" width="80px" class="img-thumnail" style="margin-bottom:90px;"/>
Try This code
<img class="im" src="data:image/jpeg;base64,'<?php echo base64_encode($row['image'] ); ?>'" height="180px" width="180px" class="img-thumnail" style="margin-bottom:90px;"/>
Related
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; ?>"/>
Try with PHP tags like below:-
<img id="img1" width="150" height="150" src="<?php echo $src;?>"/>
Reasonable solution I can think of is
<img id="img1" width="150" height="150" src="<?php echo $src; ?>"/>
but the code where you get the image source has to be above the image tag, so you have the $src.
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.
<img id="img1" width="150" height="150" src="<?= $src ?>"/>
As you can see, there is no image. What's wrong with this?
$displayProdCat .= '<div class="product">
<img src="Customer/images/product'.$ItemNo.'.jpg" width="170" height="150" />
<h3>'.$ItemName.'</h3>
<p class="product_price">Php '.$Price.'</p>
Add to Cart</div>';
Probably a wrong image url is specified. Look at the source.
I am trying to link an image using the same name as a $_GET variable, example bellow:
The $_GET
$venue = $_GET['venue'];
Is it possible to use '$venue' as the image src example being something like
<div id="imgbox">
<img src="$venue.jpg" alt="venueimage" height="150" width="250">
</div>
My attempts so far have been unsuccessful, is it possible in a similar way to this or is there an alterantive?
Thankyou
You forgot your PHP tags and echo statement:
<div id="imgbox">
<img src="<?php echo $venue; ?>.jpg" alt="venueimage" height="150" width="250">
</div>
or shorthand:
<div id="imgbox">
<img src="<?= $venue; ?>.jpg" alt="venueimage" height="150" width="250">
</div>
As pointed out by Quentin we should take this a step further and sanitize our output:
<div id="imgbox">
<img src="<?= htmlspecialchars($venue); ?>.jpg" alt="venueimage" height="150" width="250">
</div>
You should be able to use <img src="<?php echo $venue; ?>.jpg" alt="venueimage" height="150" width="250">
I forgot to sanitize the code as well. You would need to add:
<img src="<?php echo htmlspecialchars($venue); ?>.jpg" alt="venuimage" height="150" width="250">
How can I use a PHP variable inside the Javascript onclick=function?
<?php
for($i=0;$i<10;$i++){
echo '<li><div><img src='. $mobile_image_link[$i+$p] .' width="160" height="165" alt="" border="0" /></div></div></li>';
}
?>
Just concatenate the strings, and use backslashes to escape the necessary quotes:
echo '
<a href="#"
onclick="showPopUp(\''. $mobile_image_link[$i+$p].'\',
\''. $mobile_image_link[$i+$p].'\');">
<img src="'.$mobile_image_link[$i+$p].'" alt="" />
</a>'
Would result in:
<a href="#"
onclick="showPopUp('http://mylink.com/1',
'http://mylink.com/2');">
<img src="http://mylink.com/image.png" alt="" />
</a>
On a side note, please read the HTML latest specifications, setting tag style using width="", height="" and border="" is deprecated and discouraged
Simply echo php variable in javascript code:
<script type="text/javascript">
var js_variable= <?php echo $php_variable; ?>
</script>
Either use the double quotes approach (php variables are only inserted into double quote strings.
<?php for($i=0;$i<10;$i++){
echo "<li><div><img src=\"$mobile_image_link[$i+$p]\" width="160" height="165" alt="" border="0" /></div></div></li>";}
?>
or do what you already did for the img tag. You'll need to escape some quotes to make it work.
<?php for($i=0;$i<10;$i++){
echo '<li><div><img src="'.$mobile_image_link[$i+$p].'" width="160" height="165" alt="" border="0" /></div></div></li>';}
?>
<?php
for($i=0;$i<10;$i++){
$onclickvariable = "showPopUp('".$mobile_image_link[$i+$p]."','".$mobile_image_link[$i+$p]."');"
echo '<li><div><a href="#" onclick="'.$onclickvariable.'">
<img src='.$mobile_image_link[$i+$p].' width="160" height="165" alt="" border="0" /></a>
</div></li>';}
?>
I have a database that stores the path to the users image such as images/profile/950baasfaa88c.jpg. Now when i try to put this into a variable and surround it with image tags, only a blank image comes up not the image itself...
$profile_picture = $row['profile_image'];
<img src="'.$profile_picture.'" width=50 height=50 />
you haven't echo PHP
<img src="'.$profile_picture.'" width=50 height=50 />
should be
<img src="<?= $profile_picture ?>" width=50 height=50 />
you need to echo out the value
<img src="<?php echo $row['profile_image']; ?>" width=50 height=50 />