Im tring to show image1.png if it exists, else show image2.png

<?php
$image1 = images/image1.png;
$image2 = images/image2.png;

if ( $image1 < true ) {
    echo "$image1";
} else {
    echo "$image2"; 
}
?>

I am getting a Warning: Division by zero

Thank you

Recommended Answers

All 5 Replies

Member Avatar for diafol
$image1 = images/image1.png;
$image2 = images/image2.png;

if ( $image1 ) {
    echo $image1;
} else {
    echo $image2; 
}

You should get the output:

images/image1.png;

Thanks but im still getting Warning: Division by zero
i even tried

if (file_exists(image1))

with no luck

Member Avatar for diafol
$image1 = "images/image1.png";
$image2 = "images/image2.png";

Note the quotes

You want this?

if (file_exists($image1))

yep quotes was the problem Thank you but the output i would like to show the image.
sry for not making my self clear.

Got it thank you so much diafol !

$image1 = "<img src=image/image1.png>"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.