PHP Tutorial - PHP filetype() Function






Definition

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

Syntax

PHP filetype() Function has the following syntax.

filetype(filename)

Parameter

ParameterIs RequiredDescription
filenameRequired.File to check

Return

This function returns the one of seven possible values on success or FALSE on failure.

Possible return values:

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




Note

The result of this function are cached. Use clearstatcache() to clear the cache.

Example

Returns the file type of a specified file or directory


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