How can I display image instead of displayed Image path name - php

I need to display product details on my custom page,
Code:
<?php
set_time_limit(0); //THIS SCRIPT JUST INITIALS THE PROFILE TO BE RUN VIA MAGENTO ADMIN "RUN PROFILE IN POPUP". Its the same thing as click just via this file that you can run via cron
$profileId = 1; // SYSTEM - IMPORT/EXPORT - DATAFLOW PROFILES PROFILES <-- you need to go into your magento admin and grab the exact profile ID
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$sku = 10; //this sku you get it from your text box.
$_product = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(array(
'name',
'sku',
'price',
'thumbnail'
))->addAttributeToFilter('status', 1)->addAttributeToFilter('sku', array(
'in' => $sku
));
$imageHelper = Mage::helper('catalog/image');
foreach($_product as $prod)
{
$name = $prod->getName();
$price = $prod->getPrice();
$thumbnail = $imageHelper->init($prod, 'thumbnail')->resize(150, 220);
}
echo "Name: ", $name;
echo "<br />";
echo "Sku: ", $sku;
echo "<br />";
echo "Price: ", $price;
echo "<br />";
echo "Image: ", $thumbnail; ?>
How can I display product image instead of image path.

I saw your original question with the code and I think you're using Magento
So you can do it like this
Load product by ID
Mage::getModel('catalog/product')->load(.....)
Or get all products
Mage::getModel('catalog/product')->getCollection() .....
Get product image
Mage::helper('catalog/image')->init($_product, 'image') // You can change to another image code
Or get all media images
$_product->getMediaGalleryImages() // It's array, you need to loop through it to get image detail
Display like image instead a url
<img src="<?php echo $image_url ?>">
Take your time and read about this HTML Images

Here is my answer:
echo "<img src='".$thumbnail ."'>";
Thank You #Hung Vo

Related

How to take an image from My SQL database and add it to a .html page

I have some images in a database which I would like to add to a html page
This is my current code
<div class = "gridrow">
<?php
foreach (range(1, 4) as $value) {
$result = $conn->query("select * from products where product_ID = '".$value."'");
$row = $result->fetch_array();
$name_p1 = $row['product'];
$price_p1 = $row['price'];
$image = "<img src='{$row['image']}'>";
echo "<div class = 'productwindow' >";
echo "<div class = 'productimage'><".$image."></div>";
echo "<div class = 'productvar'><p>".$name_p1."</p></div>";
echo "<div class = 'productvar'><p>$".$price_p1."</p></div>";
echo "</div>";
}
?>
</div>
This is what the page looks like
These are the errors I get
How can I make these images show correctly?
You're storing image data in the database, while the img src tag wants image URLs, that's why it's getting confused and you're getting errors.
The quick way around it is to convert the image data to base64 and pipe it in the src tag like so:
$image = '<img src="data:image/png;base64,'.base64_encode($row['image']).'">';
This is at best a hack, and not a great idea for a host of reasons, it also assumes all your images are PNG.

Set user avatar from front end in wordpress

I am working on user registration page. When user upload the image then I attached that image in user meta by attachment id, now when user add the comment then his uploaded photo is not appearing in comment list beside his comment. After some search I got some information in avatar...but cant get any idea about how to upload avatar from front side?
<?php
if ( function_exists( 'get_avatar' ) ) {
echo get_avatar( $user->user_email, 50);
} else {
//alternate gravatar code for < 2.5
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=
" . md5($user->user_email) . "&default=" . urlencode($default) . "&size=" . $size;
echo "<img src='$grav_url' height='50px' width='50px' />";
}
?>
Please check with this code. This should work.

How come I cannot use bp_core_fetch_avatar() in the theme after I add filter in the plugin, wordpress buddypress?

After I do the add_filter code below in the first plugin, I cannot use bp_core_fetch_avatar() in the second plugin or in the theme, it echo out the same avatar for every user, why? How can I fix this? get_avatar can echo out different avatar base on the user except that it cannot recognize the $gender that I create in the plugin which will tell if it is a female or male, so avatar will assign base on gender . I am trying to pass some parameter like $gender that I created in the plugin, so that is why I think I should figure out to use bp_core_fetch_avatar(), by the way, does get_avatar can pass a parameter from a plugin?, I know get_avatar( $id, $size,$default, $alt). Anyway, I want to know why bp_core_fetch_avatar() echo out same avatar for every user after do the add_filter, I already add 'item_id'=>"$id". Thanks
<?php
add_filter('bp_core_fetch_avatar',array($this,'set_buddypress_avatar'), 10, 1);
?>
<?php
public function set_buddypress_avatar($html_data = ''){
$html_doc = new DOMDocument();
$html_doc->loadHTML($html_data);
$image = $html_doc->getElementsByTagName('img');
foreach($image as $data) {
$original_image = $data->getAttribute('src');
$size = $data->getAttribute('width');
$alt = $data->getAttribute('alt');
if (stripos($alt, 'Profile picture of ') === 0){ // if our alt attribute has "profile picture of" in the beginning...
$name = str_replace('Profile picture of ', '', $alt);
} else if (stripos($alt, 'Profile photo of ') === 0){ // or profile photo of...
$name = str_replace('Profile photo of ', '', $alt);
} else { // if there is some problem - just assign alt to name
$name = $alt;
}
}
?>
I want to know why bp_core_fetch_avatar() echo out same avatar for
every user after do the add_filter
Because you added a filter to a core BP function.
Try removing the filter after you are finished with it in your class.
remove_filter#Example

How to Displaying an image with path stored in Database?

I have stored images path in database and images in project folder. Now i am trying to view all IMAGES with their PRODUCTS in my HTML template. I have written the following code and its given me an empty images box in the output and when i open that image box in the new tab, it opens the following URL.
http://localhost/cms/1
Kindly tell me the way of referring images in 'img src ' tag.
include 'connect.php';
$image_query = "select * from product_images";
$image_query_run = mysql_query($image_query);
$image_query_fetch = mysql_fetch_array($image_query_run);
if (!$query=mysql_query ("select product_id,name from products")) {
echo mysql_error();
} else {
while ($query_array = mysql_fetch_array($query)) {
echo '</br><pre>';
$product_id = $query_array['product_id'];
echo "<a href='single_product.php?product_id=$product_id' >";
print_r ($query_array['name']);
echo "</a>";
echo "<img src=". $image_query_fetch
['images'] ." alt=\"\" />";
echo '</pre>';
}
}
} else {
echo "You need to Log in to visit this Page";
}
Add your local image path before source
example
echo "<img src='http://localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />";
*Use PHP *
<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
You can use the HTML base tag to set a base URL that relative URLs will be resolved from.
See -> http://www.w3schools.com/tags/tag_base.asp

How do I get the featured image description from my wordpress page?

So I set up my wordpress theme to allow users to upload featured images, and Im building my index page to display selected pages' featured images but would also like to display the description of the image.
The thing is, Im not using the loop, Im pulling the page IDs using wordpress's settings API as options.
So displaying the featured images is done like this:
<?php $bucket_options = get_option('frontpage_display_options'); ?>
<?php $page_one = $bucket_options['frontpage_bucket_one']; ?>
<?php $page_one = get_post($page_one); ?>
<?php if (has_post_thumbnail($page_one->ID)) : ?>
<?php echo get_the_post_thumbnail($page_one->ID, 'bucket'); ?>
<?php endif; ?>
I keep reading that this will work:
echo get_post(get_the_post_thumbnail_id($page_one->ID))->post_content;
or this:
echo get_post(get_the_post_thumbnail($page_one->ID))->post_content;
But neither of them displays anything
That capability is awaiting a new release: http://core.trac.wordpress.org/ticket/12235
But a solution that is floating around is to create a function in functions.php:
function the_post_thumbnail_caption() {
global $post;
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
if ($thumbnail_image && isset($thumbnail_image[0])) {
echo '<span>'.$thumbnail_image[0]->post_excerpt.'</span>';
}
}
And then call the_post_thumbnail_caption();
This works for me. It echo's the title, caption and description of the featured image.
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
echo '<p>' . get_post(get_post_thumbnail_id())->post_title . '</p>';
echo '<p>' . get_post(get_post_thumbnail_id())->post_excerpt . '</p>';
echo '<p>' . get_post(get_post_thumbnail_id())->post_content . '</p>';
endif;
?>

Categories