is_file()
is_file() — Tells whether the filename is a regular file.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Tells whether the given file is a regular file. If filename is a symbolic link, it will resolve the symlink and will give information about the referred file.
Signature
is_file(string $filename): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $filename | string | Path to the file. |
Return value
Returns true if the filename exists and is a regular file, false otherwise. Note: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB. Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.
Example
A runnable snippet:
var_dump(is_file('a_file.txt')) . "\n"; var_dump(is_file('/usr/bin/')) . "\n";
Output:
bool(true) bool(false)
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page is_file() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.