(Sorry if you’ve seen this is pieces. This site is hard to use on a phone.)
I’m working on a section of my site for herbs with dynamically created pages and I’m trying to do an if else tag to show one picture if it exists and another picture if it doesn’t.
This is my current code for the image of else
$imgsrc = "/new/herbs/pages/imgs/$herb.jpg";
echo "<img src='$imgsrc' alt='$herb'>";
if (file_exists("$imgsrc"))
echo "<img src='$imgsrc' alt='$herb'>";
else
echo "<img src='new/herbs/pages/imgs/imgherb.jpg' alt='$herb'>";
For some reason, it doesn’t recognize that the file exists and still shows the image in the else tag.
I have made this into a function, I’ve added curly brackets, I’ve used the manual link to the folder of images, and I’ve used $_SERVER[‘DOCUMENT_ROOT’]. I still have the same issue.
If I link to the image manually, it works fine; with and without the variable $imgsrc. So I am at a total loss as to what it could be.
Any ideas?