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 filedir: directorychar: character special devicelink: symbolic linkfifo: FIFO (named pipe)block: block special deviceunknown: unknown file type
Code
Let’s look at a coded example of this function:
main.php
hello.txt
<?php// text fileecho filetype("hello.txt");?>
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved