php8.5
Home/ Manual/ filesystem / functions/ file_exists

file_exists

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Checks whether a file or directory exists

Description

file_exists(string $filename): bool

Checks whether a file or directory exists.

Parameters

filename

Path to the file or directory.

On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares.

Return Values

Returns true if the file or directory specified by filename exists; false otherwise.

Note

This function will return false for symlinks pointing to non-existing files.

Note

The check is done using the real UID/GID instead of the effective one.

32bit

Errors/Exceptions Failure

Examples

Testing whether a file exists

php
<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
?>

Notes Clearstatcache Stat

See Also

Source: reference/filesystem/functions/file-exists.xml · from the official PHP manual (php/doc-en)