I need to make an image gallery with a variable number of images. I’m making a loop that checks for a lot of image names, like image1, image2, image3 and so on.
I need to make a condition so that it doesn’t show a missing file icon if an image doesn’t exists. How can I check if the file exists and if true show it?
Thanks.
I think there are several PHP functions that will let you check for the existence of a file. One of them is
file_exists:Another function that you can use is
is_file. According to the documentation:So in your code you can do something like: