The is_file() function in PHP checks whether the given filename is a regular file.
is_file(string $name): bool
This function takes a single parameter.
name: This specifies the path to the file we want to check.
The is_file() function returns true if the provided filename exists and is also a regular file. Otherwise, it returns false.
The code below shows how to use the is_file function.
<?php$name = "website.txt";if(is_file($name)){echo ("$name is a regular file");}else{echo ("$name is not a regular file");}echo "\n";$name2 = "edpresso.txt";if(is_file($name2)){echo ("$name2 is a regular file");}else{echo ("$name2 is not a regular file");}?>
In the above code, two filenames have been specified, website.txt and edpresso.txt. The former filename does not exist, so the is_file function returns false.
On the other hand, the function returns true when called with expresso.txt since it is a valid file.
This function produces cache output. We have to clear the cache by using the
clearstatcache()function.
Free Resources