PHP is_file() Examples


is_file() function checks whether the argument is a existing file or not. It returns TRUE if it is, otherwise FALSE.

For example, if you want to do something to all file under a directory which contains both files and subdirectories.

<?PHP
	$dir = "/usr/";
    if ($handle = opendir($dir))
	{
		while (false !== ($entry = readdir($handle)))
		{
			$file = $dir . "$entry";
            if (is_file($entry))	echo "$entry is a file\n";		
		}
	}
?>

is_dir() function can be used to check whether the argument is a existing directory.
<?PHP
	$dir = "/usr/";
	if (is_dir($dir)) echo "$dir is a directory\n";
?>