Home >Backend Development >PHP Tutorial >Getting started example of using mkdir to create multi-level directories in PHP
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: set the directory The permissions, the default is 0777, which means the maximum possible access rights;
The third parameter: true means that the creation of multi-level directories is allowed.
Example code (supports creating Chinese directories):
<?php header("Content-type:text/html;charset=utf-8"); //要创建的多级目录 $path="dai/php/php学习"; //判断目录存在否,存在给出提示,不存在则创建目录 if (is_dir($path)){ echo "对不起!目录 " . $path . " 已经存在!"; }else{ //第三个参数是“true”表示能创建多级目录,iconv防止中文目录乱码 $res=mkdir(iconv("UTF-8", "GBK", $path),0777,true); if ($res){ echo "目录 $path 创建成功"; }else{ echo "目录 $path 创建失败"; } } ?>
For more introductory examples of using mkdir to create multi-level directories in PHP, please pay attention to the PHP Chinese website!