PHP is_dir of determines whether a given file name is a directory

  • 2020-03-31 20:39:25
  • OfStack

instructions
bool is_dir (string $filename)
Returns TRUE if the file name exists and is a directory. If filename is a relative path, it is checked against the current working directory.

Note: the result of this function will be cached. See clearstatcache() for more information.

The is_dir () example 1
 
<? 
var_dump(is_dir('a_file.txt')) . "n"; 
var_dump(is_dir('bogus_dir/abc')) . "n"; 
var_dump(is_dir('..')); //one dir up 
?> 

The above example will output:

Bool (false)
Bool (false)
Bool (true)

The is_dir () Example 2
 
<?php 
$file = "images"; 
if(is_dir($file)) 
{ 
echo ("$file is a directory"); 
} 
else 
{ 
echo ("$file is not a directory"); 
} 
?> 

Output:
If the directory images exists, the output is as follows.
Images is a directory

Related articles: