is_dir()
is_dir() — Tells whether the filename is a directory.
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.
Signature
is_dir(string $filename): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $filename | string | Path to the file. If filename is a relative filename, it will be checked relative to the current working directory. If filename is a symbolic or hard link then the link will be resolved and checked. If you have enabled open_basedir further restrictions may apply. |
Return value
Returns true if the filename exists and is a directory, false otherwise.
Example
A runnable snippet:
var_dump(is_dir('a_file.txt')); var_dump(is_dir('bogus_dir/abc')); var_dump(is_dir('..')); //one dir up
Output:
bool(false) bool(false) bool(true)
See also
chdir(), dir(), opendir(), is_file(), is_link()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page is_dir() (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.