I need to see if a specific image exists on my cdn.
I've tried the following and it doesn't work:
if (file_exists(http://www.example.com/images/$filename)) {
echo "The file exists";
} else {
echo "The file does not exist";
}
Even if the image exists or doesn't exist, it always says "The file exists". I'm not sure why its not working...
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