PHP: How to check if image file exists?

You need the filename in quotation marks at least (as string):

if (file_exists('http://www.mydomain.com/images/'.$filename)) {
 … }

Also, make sure $filename is properly validated. And then, it will only work when allow_url_fopen is activated in your PHP config

Leave a Comment