PHP is_file() Function

Definition and Usage

The is_file() function checks if the specified filename is a normal file.

Syntax

is_file(file)
Parameters Description
file Required. Specifies the file to be checked.

Description

If the file exists and is a normal file, it returns true.

Tips and Comments

Note:The result of this function will be cached. Please use clearstatcache() to clear the cache.

Instance

Example 1

<?php
$file = "test.txt";
if(is_file($file))
  {
  echo ("$file is a regular file");
  }
else
  {
  echo ("$file is not a regular file");
  }
?>

Output:

test.txt is a regular file

Example 2

<?php
var_dump(is_file('a_file.txt')) . "\n";
var_dump(is_file('/usr/bin/')) . "\n";
?>

Output:

bool(true)
bool(false)