Home >Backend Development >PHP Problem >How to determine if a folder exists in php and create it if it does not exist
php determines whether the folder exists, and creates it if it does not exist: first create a PHP sample file; then define a mkdirs method; finally use the "mkdirs("aa01");" method to determine the folder and create it Just create it.
Recommended: "PHP Video Tutorial"
php determines whether the folder exists and then creates it
The code is as follows:
function mkdirs($dir, $mode = 0777) { if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE; if (!mkdirs(dirname($dir), $mode)) return FALSE; return @mkdir($dir, $mode); } mkdirs("aa01");
The default mode is 0777, which means the maximum possible access rights.
The above is the detailed content of How to determine if a folder exists in php and create it if it does not exist. For more information, please follow other related articles on the PHP Chinese website!