What is the filetype function in PHP?

The filetype() function is a built-in function in PHP that returns the file type of a given file.

Syntax

filetype(filename)

Parameters

filename: A required parameter that refers to the filename for which we want to check the file type.

Return value

This method returns the file type from the following list of values:

  • file: regular file
  • dir: directory
  • char: character special device
  • link: symbolic link
  • fifo: FIFO (named pipe)
  • block: block special device
  • unknown: unknown file type

Code

Let’s look at a coded example of this function:

main.php
hello.txt
<?php
// text file
echo filetype("hello.txt");
?>

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved