English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and Example of PHP filetype() Function

PHP Filesystem Reference Manual

The filetype() function can return the file type of a specified file or directory. If successful, this function can return one of seven possible values; if it fails, it can return false.

Syntax

string filetype ( string filename )

Possible values are fifo, char, dir, block, link, file, and unknown.

 If an error occurs, FALSE is returned. The filetype() function may also produce an E_NOTICE message if the stat call fails or the file type is unknown.

Online Example

<?php
   echo filetype("/PhpProject/sample.txt");  // file
   echo "\n";
   echo filetype("/PhpProject/");  // dir
?>
Test and See‹/›

Output Result

file
dir

PHP Filesystem Reference Manual