filetype()

filetype() — Gets file type.

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

filetype(string $filename): string|false

Parameters

ParameterTypeWhat it takes
$filenamestringPath to the file.

Return value

Returns the type of the file. Possible values are fifo, char, dir, block, link, file, socket and unknown. Returns false if an error occurs. filetype() will also produce an E_NOTICE message if the stat call fails or if the file type is unknown.

Example

A runnable snippet:

echo filetype('/etc/passwd'); echo "\n"; echo filetype('/etc/');

Output:

file dir

See also

is_dir(), is_file(), is_link(), file_exists(), pathinfo(), stat()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page filetype() (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.