PHP default mkdir can only create one level of directory at a time, if you create a div/css/layout directory under the current directory, you need to create a div layer by layer, then create DIV/CSS and then create Div/css/layout. However, we hope that the program will help us to complete the process automatically.
In fact, the idea is very simple, 1. First determine whether the div directory exists, does not exist to create; 2. Determine if the subdirectory div/css exists, cannot exist, and 3. In the second step, the function itself is called recursively as a sub-directory. can also be in reverse order, 1. First determine whether the lowest-level directory div/css/layout exists, 2. Determine whether Div/css/layout's upper-level directory DIV/CSS exists, does not exist, and is recursive with DIV/CSS as a parameter.
Here is the program code for PHP function mkdir:
<?
function Mkdirs ($dir)
{
if (!is_dir ($dir))
{
if (!mkdirs (DirName ($dir)))
{return false;
}
if (!mkdir ($dir, 0777))
{
return false;
}
}
return true;
}
Mkdirs (' div/css/layout '); In the same vein, PHP uses RmDir and unlink to recursively delete the multilevel directory code:
function Rmdirs ($dir)
{$d = dir ($dir);
while (false!== ($child = $d->read ()))
{if ($child! = '. ' && $child! = ' ... ')
{if (Is_dir ($dir. '/'. $child)) Rmdirs ($dir. '/'. $child); else unlink ($dir. '/'. $child);
}
} $d->close (); RmDir ($dir);
}
?>
The above code example is the PHP function mkdir implementation to create a multilevel directory of the specific method.
Create a multilevel directory using PHP function mkdir