Home  >  Article  >  Backend Development  >  Getting started example of using mkdir to create multi-level directories in PHP

Getting started example of using mkdir to create multi-level directories in PHP

高洛峰
高洛峰Original
2016-12-21 15:25:071283browse

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!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn