PHP filetype() Function

Definition and Usage

The filetype() function returns the type of the specified file or directory.

If successful, it returns 7 possible values. If failed, it returns false.

Possible values:

  • fifo
  • char
  • dir
  • block
  • link
  • file
  • unknown

Syntax

filetype(filename)
Parameter Description
filename Required. Specifies the file to be checked.

Tips and Comments

Tip:The result of this function will be cached. Please use clearstatcache() to clear the cache.

Instance

Example 1

<?php
echo filetype("test.txt");
?>

Output:

file

Example 2

<?php
echo filetype("images");
?>

Output:

dir