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.
Related
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
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
I am trying to add custom html to a 404 page in wordpress.
<?php
$filename = "/find";
if (!file_exists($filename))
echo $filename, " display html2 ";
elseif (!is_dir($filename))
echo $filename, " display html1 ";
?>
If someone visits http://www.demosite.com/about/whatever = Display HTML 1
If someone visits http://www.demosite.com/find/whatever = Display HTML 2
Is this even possible with PHP and HTML?
<?php
$filename = "/find";
if (is_dir($filename)){
echo $filename, " display html1 ";
include('html1.html');
}
else{
echo $filename, " display html2 ";
include('html1.html');
}
?>
This code checks for the folder "find" if it exists it shows html1 else html2.
I guess the better option for you will be this :
Use htaccess when user browse http://yourdomain/about/whatever show the contents from http://yourdomain/page.php?p=about&var=whatever
And get the value of p in your page using $_GET['p'], and show the html accordingly
if($_GET['p'] == "find"){
include('html1.html');
}else{
include('html2.html');
}
<?php
$i = 0;
$page = get_the_content();
$doc=new DOMDocument();
$doc->loadHTML($page);
$xml=simplexml_import_dom($doc);
$images=$xml->xpath('//img');
foreach ($images as $img) {
list($width, $height, $type, $attr) = getimagesize($img['src']);
if ($height > 149 ) {
echo '<img src="' . $img['src'] . '" alt=" ' . $img['alt'] . ' - funny and hot pictures" title=" ' . $img['title'] . ' - funny fail picture dump" onerror=\'this.style.display="none" \'><br>';
$i++;
if ($i == 3 ) { break;}
}
else
{
// don't display
}
}
?>
I replaced the "<?php the_content(); ?>" piece of code with the one above. It's supposed to strip out all of the text in my post and just leave the images which it does nicely. But when I embed a video the php breaks. How would I allow posts to show youtube videos?
You should look into using custom fields:
http://codex.wordpress.org/Custom_Fields
There is a great plugin that creates good admin control panels for them too:
http://wordpress.org/extend/plugins/advanced-custom-fields/
You could use a custom field to specifically put a video into the page.
Is there a particular reason you want to strip the text out of the post? - e.g. could you just not put text in the post at all? - or could the text be put into the excerpt instead, or into a custom field so that you don't have to over complicate the output code?
i am making a login system with registration and a profile page in php and i am trying to make a profile picture work.
if the user has not uploaded a profile picture yet then make it show a "no profile picture" image if the user has uploaded a profile picture make make it show the image that he has uploaded.
Right now it only show the default picture, noprofile.png.
< img src="uploads/< ? echo "$username" ? >/noprofile.png">
i want it to show icon.png if icon.png has been uploaded and if it hasnt been uploaded make it show, noprofile.png.
Just run it through the logic, using file_exists:
$image="/path/on/local/server/to/image/icon.png";
$http_image="http://whatever.com/url/to/image";
if(file_exists($image))
{
echo "<img src=\"$http_image\"/>\n";
}
else
{
echo "<img src=\"uploads/$username/noprofile.png\"/>\n";
}
Check to see if the file has been uploaded by using file exists. If the file exists, use that url else use the default noprofile.png.
you could make a column in the DB to store a value if it has been uploaded or not.
OR
you could see if the file exists.
<?php
if (file_exists('uploads/' . $username . '/icon.png')) {
echo '<img src="uploads/' . $username . '/icon.png">';
}
else {
echo '<img src="uploads/' . $username . '/noprofile.png">';
}
?>
<?php
$img = file_exists(sprintf('/path/to/uploads/%s/icon.png', $username))
? 'icon.png' : 'noprofile.png';
?>
<img src="uploads/<?php printf('%s/%s', htmlspecialchars($username), $img) ?>">
You could use http://us3.php.net/file_exists to check if the image file is there.
Another alternative is - assuming you keep your user info in a database - have a column with the image name. Since you have to retrieve info from your user table anyway, check to see if that column is NULL or blank. If it is, the user has not uploaded an image yet.
Then, in the page you display the user photo, you might have code something like this:
$userPhoto = ($photoName)? $photoName : 'placeholder';
echo '<img src="uploads/'.$userPhoto.'.png" />
Assuming the filepaths are correct, here's what you do...
<?php $filename = "uploads/".$username;
$imgSrc = file_exists($filename) ? $filename : "uploads/noprofile.png"; ?>
<img src=<?php echo $imgSrc?>
Use onerror attribute in img tag
<img onerror="this.src= 'img/No_image_available.png';" src="<?php echo $row['column_name ']; ?>" />