• PHP Video Tutorials

PHP - Function is_file()



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

Syntax

bool is_file ( string $filename )

This function can return true if the filename exists and is a regular file, or false otherwise.

Example-1

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

Output

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

Example-2

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

Output

bool(false)
bool(false)
php_function_reference.htm
Advertisements