0

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

Edited by Tko_1

2
Contributors
5
Replies
9
Views
4 Years
Discussion Span
Last Post by Tko_1
0
$image1 = images/image1.png;
$image2 = images/image2.png;

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

You should get the output:

images/image1.png;

0

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

if (file_exists(image1))

with no luck

Edited by Tko_1

0
$image1 = "images/image1.png";
$image2 = "images/image2.png";

Note the quotes

You want this?

if (file_exists($image1))

Edited by diafol

0

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

0

Got it thank you so much diafol !

$image1 = "<img src=image/image1.png>"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.