$var = "http://site.com/image.png";
if (file_exists($var))
echo 'yes';
else
echo 'no';
Why does this script always returns false?
$var = "http://site.com/image.png";
if (file_exists($var))
echo 'yes';
else
echo 'no';
Why does this script always returns false?
On
The $var variable should describe a path on the system, not a URL. For example
$var = "/var/www/html/image.png";
Because that's not actually a file, rather it's a URL.
Up until PHP5, the
file_existsfunction was intended to detect whether a file or directory exists.At PHP5, support was introduced to allow support for some URL wrappers, as per the note on this page:
The wrappers are detailed here but, unfortunately, the
httpone does not supportstat, a pre-requisite to allowingfile_existsto work.If you're running on the server, you could possibly convert it using
$_SERVER['DOCUMENT_ROOT']or find another way to locate it on the file system.