When we want to add a multilevel catalog to our website, we can use the
PHP function mkdir parameters and descriptions
Path is required. Specifies the name of the directory to create.
Mode required. Set permissions. The default is 0777.
Recursive required. Specifies whether recursive mode is set.
Context required. Specifies the environment for file handles. Context is a set of options for modifying the behavior of a stream.
Description
PHP function mkdir Attempt to create a new directory specified by path.
The default mode is 0777, which means the maximum possible access rights.
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.
http://www.bkjia.com/PHPjc/446279.html www.bkjia.com true http://www.bkjia.com/PHPjc/446279.html techarticle when we want to add multi-level catalogs to our site, we can use PHP functions to mkdir parameters and describe the path required. Specifies the name of the directory to create. Mode required. Set permissions. The Silent ...