PHP for directory creation, there is a special function mkdir (): Success, return True, failed, return false
The function mkdir has four parameters:
Path: The name of the directory to create
Mode: Permissions. Default is 0777 (maximum permissions)
Recursive: Sets whether a multilevel directory can be created (true: Can, false: not)
Context: The environment for file handles. Context is a set of options (rarely used) to modify the behavior of a stream
Here are two ways to introduce PHP to create a multilevel directory, the details are as follows:
1. The idea of using recursion
function Mkdirs_2 ($path) {
if (!is_dir ($path)) {
mkdirs_2 (dirname ($path));
if (!mkdir ($path, 0777)) {return
false;
}
}
return true;
}
/* http://www.manongjc.com/article/1331.html * *
$path 2 = ' sdfs/sds/sds/s/s/sss ';
Var_dump (Mkdirs_2 ($path 2)); True
1. The idea is primarily to use recursion, first to create DIR, to create DIR/CSS, to create ....
2. Recursion is the process of the stack, so first let, Dir/css/js/php/ok first into the stack, then it will be the last stack ... The rest will not be spoken.
3.dirname (path) returns the value of path in addition to the last directory, that is, the first return is: dir/css/js/php,,, return to Dir/css/js for the second time,,, the last time.
2. Directly using mkdir () to create, the third parameter must be true to automatically create multilevel catalogs
function Mkdirs_1 ($path, $mode = 0777) {
if (Is_dir ($path)) {return
' cannot be created, is already a directory ';
} else{
if (mkdir ($path, $mode, True)) {return
' create success ';
} else{return
' Create failed ';
}} /* http://www.manongjc.com/article/1332.html * *
$path 1 = ' a/b/c/d/e ';
Var_dump (Mkdirs_1 ($path 1)); String ' Create Success ' (LENGTH=12)
The above is a small set to introduce PHP to create a multi-level directory of two methods, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!