PHP filetype()Function


PHP Filesystem 参考手册Complete PHP Filesystem Reference

Definition and Usage

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

If successful, the function returns one of 7 possible values. If it fails, it returns FALSE.

Possible return values:

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

Syntax

filetype(filename)

Parameter Description
filename Required. Specifies the file to be checked.


Tips and Notes

Note:The results of this function are cached. Use clearstatcache() to clear the cache.


Example 1

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

The code above will output:

file


Example 2

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

The code above will output:

dir


PHP Filesystem 参考手册Complete PHP Filesystem Reference Other Extensions