PHP provides built-in function is_dir to check if the passed-in Path parameter is a directory and returns true if it is a directory. This means that the parameter passed in is either a file or not, so the current parameter cannot be said to be a folder or a file. It is also important to note that the parameters support relative paths and absolute paths.
Function: Is_dir ()
Function: Determine if a given file name is a directory
Description
BOOL Is_dir (String $filename)
Returns TRUE if the file name exists and is a directory.
If filename is a relative path, the relative path is checked according to the current working directory.
Note: The result of this function is cached. See Clearstatcache () for more information.
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 example above will output:
BOOL (FALSE)
BOOL (FALSE)
BOOL (TRUE)
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 exists images, the output is:
Images is a directory
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP implementation method of extracting Chinese and English initial letters
How to build an intelligent bar chart program in PHP
The definition and usage of headers in PHP header