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

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP is_file() Function Usage and Example

PHP Filesystem Reference Manual

The is_file() function can check if the specified file is a normal file.

Syntax

bool is_file ( string $filename )

This function can return true if the filename exists and is a normal file, otherwise it returns false.

Example1

<?php
   $file = "/PhpProject/php/phptest.txt";
   if(is_file($file)) {
       echo("$file is a normal file");
   } else {
       echo("$file is not a normal file");
   }
?>

Output Result

/PhpProject/php/phptest.txt is a normal file

Example2

<?php
   var_dump(is_file("/PhpProject/simple.txt"))  .  "\n";
   var_dump(is_file("/PhpProject/php"))  .  "\n";
?>

Output Result

bool(false)
bool(false)

PHP Filesystem Reference Manual