Home>Article>Backend Development> How to determine whether the path is a folder or a file in php
In PHP, you can use the if statement and the is_dir() and is_file() functions to determine whether the path is a folder or a file. The syntax "if(is_dir($file)){echo "is a folder"; }else if(is_file($file)){echo "is a file"}".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php determines whether the path is a folder or File
In PHP, you can use the if statement and the is_dir() and is_file() functions to determine whether the path is a folder or a file.
The is_dir() function can check whether the specified file is a directory. If the directory exists, this function returns TRUE.
The is_file() function can check whether the specified file is a regular file. If the file is a regular file, this function returns TRUE.
Implementation code:
Output result:
If $f# If the value of ##ileis changed to "img", it will output:
PHP Video Tutorial"
The above is the detailed content of How to determine whether the path is a folder or a file in php. For more information, please follow other related articles on the PHP Chinese website!