Home > Article > Backend Development > How to determine if a directory exists in php and create it if it does not exist
php method to determine whether the directory exists, and create it if it does not exist: first create a PHP sample file; then use the "function mkFolder($path){...}" method to determine whether the directory exists, and if it does not exist, then Just create the function.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How does PHP determine whether a directory exists or create it if it does not exist?
PHP determines whether the directory exists. If it does not exist, create it.
The code is as follows:
function mkFolder($path) { if(!is_readable($path)) { is_file($path) or mkdir($path,0700); } }
is_file() function checks whether the specified file name is a normal file.
mkdir() function creates a directory. Returns true if successful, false otherwise.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine if a directory exists in php and create it if it does not exist. For more information, please follow other related articles on the PHP Chinese website!