Is it possible to display an alternative image please?

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
IChaps
New php-forum User
New php-forum User
Posts: 123
Joined: Tue Mar 01, 2016 3:07 pm

Tue Nov 06, 2018 3:37 pm

Hello.

I'd just like to enquire if an image is not available for some reason, is it possible to show an alternative image instead?

At present I've written

Code: Select all

<img src="/user/images/<?=row['myimage'?>", width="75",  height="75", alt="scr='/system/graphics/noimage.png'">
At present, it displays the text scr='/system/graphics/noimage.png' but I'd like it to display the noimage.png graphic.


Thank You.

User avatar
WebguruInfosystems
New php-forum User
New php-forum User
Posts: 3
Joined: Wed Dec 05, 2018 9:47 pm
Location: Y8, Block - EP, Sector V, Salt Lake Kolkata - 700091, INDIA
Contact:

Thu Dec 06, 2018 4:33 am

Yes you can always use alternate image if your image does not exist. You can use file_exists() php function.

$image="path of image/image.png";

if(file_exists($image))
{
echo "<img src="’.$image.’"/>";
}
else
{
echo "<img src="path of your default image/noprofile.png">";
}

IChaps
New php-forum User
New php-forum User
Posts: 123
Joined: Tue Mar 01, 2016 3:07 pm

Fri Dec 07, 2018 2:20 am

Thank yo very much for your reply.

Post Reply