Home >Backend Development >PHP Tutorial >Getting started example of using mkdir to create a multi-level directory in PHP_PHP tutorial
First introduce the mkdir() function:
mkdir($path,0777,true);
The first parameter: required, represents the path of the multi-level directory to be created;
The second parameter: sets the permissions of the directory, the default is 0777, which means the maximum possible access rights;
No. Three parameters: true means allowing the creation of multi-level directories.
Example code (supports creation of Chinese directories):
header("Content-type:text/html;charset=utf-8");
//Multi-level directory to be created
$path="dai/php/php learning";
//Determine whether the directory exists. If it does, a prompt will be given. If it does not exist, create the directory
if (is_dir($path)){
echo "Sorry! Directory" . $path . "Already exists!";
}else{
//The third parameter is "true", which means that multi-level directories can be created. iconv prevents Chinese directories from being garbled
$res=mkdir(iconv("UTF-8", "GBK", $path),0777,true);
if ($res){
echo "Directory $path was created successfully";
}else{
echo "Directory $path was created failed";
}
}
?>