This example describes how PHP uses mkdir to create a multilevel catalog. Share to everyone for your reference, specific as follows:
PHP uses mkdir () to create a multilevel directory, which is very useful compared to your own first-level creation.
The following is a description of the functions in the PHP manual:
Copy Code code as follows:
BOOL MkDir (string $pathname [, int $mode = 0777 [, bool $recursive = False [, resource $context]]]
The return value is of type bool.
First parameter: must, represents the path of the multilevel directory to be created;
The second parameter: Set the directory permissions, the default is 0777, meaning the most likely access rights;
Third parameter: True indicates that multilevel catalogs are allowed to be created.
Note: You can create a Chinese catalog
Copy Code code as follows:
mkdir (Iconv ("Utf-8", "GBK", $path), 0777,true);
Need to use Iconv transcoding
The complete sample code is as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");
The multilevel directory to create
$path = "dai/php/php learning";
To determine whether a directory exists, give a hint, and do not exist create a directory
if (Is_dir ($path)) {
echo "Sorry!" Directory. $path. "Already there!" ";
} else{
//The third parameter is "true" to create a multilevel directory, iconv prevent Chinese directory garbled
$res =mkdir (iconv ("UTF-8", "GBK", $path), 0777,true);
if ($res) {
echo "directory $path create Success";
} else{
echo "directory $path create Failed";
}
? >
I hope this article will help you with the PHP program design.