Storing image path in a variable - php

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 />

Related

Assign Image SRC in php

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 ?>"/>

Can't display the image in browser

$images['result'][0]['image_path'] - here I have path of image. It is in public folder.
<img width="150" height="150" alt="150x150" src="<?php BASEPATH."../public/" echo $images['result'][0]['image_path'];?>" />
Can anyone help me to display this image?
Try This,
<img width="150" height="150" alt="150x150" src="<?php echo base_url('your/Folder/Structure/').$images['result'][0]['image_path'];?>" />
First concate your file name with path which causing the issue.
base_url() will also help you to fetch/show your image

Trying to add and image to view order page magento 2

I'm trying to add a thumbnali image to the view order page in the account section with the following code but it doesn't do anything:
<td>
<?php $_product = Mage::getModel('catalog/product')->load($_item->getId()); ?>
<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="" />
</td>
Any ideas why this is not working?
Try the codes given below:
First load the product
$_product = Mage::getModel('catalog/product')->load($_item->getProductId());
Then show the thumbnail where you want using the code given below
<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75, 75); ?>" alt="<?php echo $this->htmlEscape($_item->getName()); ?>" border="0" width="75" />

i'm taking image url from database. But it is not working in img tag in php

The name of the column is : link. variable-type:varchar.
<img src="<?php echo$link;?>" style="width:300px; height:400px;" />
</html>
Your echo command could be missing an ";"
$link=$row['link'];
<img src="<?php echo $link; ?>" style="width:300px; height:400px;" />
Should work better.

Linking nightmare on my street

<img src="…/<?php echo "$ArtFilePath"; ?>">
gives me this. It’s actually the one I want only without the …
http://markdinwiddie.com/PHP2012/.../artwork/Drawings/Boy.jpg
<img src="../<?php echo "$ArtFilePath"; ?>">
give me this
http://markdinwiddie.com/artwork/Drawings/Boy.jpg
<img src="/../<?php echo "$ArtFilePath"; ?>">
gives me this
http://markdinwiddie.com/artwork/Drawings/Boy.jpg
and
<img src="/…/<?php echo "$ArtFilePath"; ?>">
gives me this
http://markdinwiddie.com/.../artwork/Drawings/Boy.jpg
What I need is
http://markdinwiddie.com/PHP2012/artwork/Drawings/Boy.jpg
Who knows the order of dots and slashes?
Since $artFilePath == "artwork/Drawings/Boy.jpg", you want either:
Relative urls
Provided your php file is within /PHP2012/ this will work. It will even work if you rename the directory
<img src="<?php echo $ArtFilePath ?>" />
Which outputs
<img src="artwork/Drawings/Boy.jpg" />
Absolute urls
<img src="/PHP2012/<?php echo $ArtFilePath ?>" />
Which outputs
<img src="/PHP2012/artwork/Drawings/Boy.jpg" />
if the webpage is within the PHP2012 folder: http://markdinwiddie.com/PHP2012/
and your image is in artwork/Drawings/Boy.jpg within the PHP2012 folder
can't you just do <img src="<?php echo "$ArtFilePath"; ?>">

Categories