PHP Tutorial - PHP is_file() Function






Definition

The is_file() function checks whether the specified file is a regular file.

Syntax

PHP is_file() Function has the following syntax.

is_file(file)

Parameter

ParameterIs requiredDescription
fileRequired.File to check

Return

This function returns TRUE if it is a file.

Note

The result of this function are cached. Use clearstatcache() to clear the cache.





Example

is_file() returns true if the string parameter is a file.

For example, to check whether it is a file:


<?PHP//from   w w  w  .j  a va  2s.c o m
      $filename = 'c:\boot.ini'; // Windows
      $filename = '/etc/passwd'; // Unix

      if (is_file($filename)) {
             print 'is File !';
      } else {
             print 'is not a File!';
      }
      
?>

The code above generates the following result.