0

In my webroot, i have a file called exists.php in which is this code to check if a file exists:

$filename = 'http://www.domain.nl/contact.php';
if (file_exists($filename))
    {
        echo "Document ".$filename." found...<br><br><br>";
    }
    else
    {
        echo "Document ".$filename." not found...<br><br><br>";
    };

The file contact.php DOES exist but when calling exists.php he echoes: Document not found
When changing code to this:

$filename = 'contact.php';
if (file_exists($filename))
    {
        echo "Document ".$filename." found...<br><br><br>";
    }
    else
    {
        echo "Document ".$filename." not found...<br><br><br>";
    }; 

Then it echoes: Document found.

Why does this not work with an absolute path?

1 Answers1

3

file_exists() only works on stream wrappers that support the stat function.

These include:

  • file://
  • ftp://
  • php://memory
  • php://temp
  • phar://
  • ssh2.sftp
  • rar://

http:// is not supported

Mark Baker
  • 199,760
  • 28
  • 325
  • 373
  • You forgot `ftp://` (since PHP 5.0). – Gumbo Jun 15 '14 at 17:56
  • 1
    actually php://temp and php://memory don't work. Not that they can't be stated, but the way their abstractions work there is nothing to stat unless the file handle is around. So while file functions that need 'stat' that take in file handles will work. The ones that take paths like file_exists will not. – cythrawll Dec 15 '16 at 19:53