Home  >  Article  >  Backend Development  >  How to use mkdir to create multi-level directories in PHP, _PHP tutorial

How to use mkdir to create multi-level directories in PHP, _PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:02:39892browse

How PHP uses mkdir to create a multi-level directory,

The example in this article describes how PHP uses mkdir to create a multi-level directory. Share it with everyone for your reference, the details are as follows:

Using mkdir() in PHP can create multi-level directories. Compared with the previous level-by-level creation, this function is very easy to use.

The following is the function introduction in the PHP manual:
Copy code The code is as follows: bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
The return value is of bool type.

The first parameter: required, represents the path of the multi-level directory to be created;

The second parameter: Set the permissions of the directory, the default is 0777, which means the maximum possible access rights;

The third parameter: true means allowing the creation of multi-level directories.

Note: You can create a Chinese directory Copy the code The code is as follows: mkdir(iconv("utf-8", "gbk", $path),0777,true); required Use iconv to transcode

The complete sample code is as follows:

<&#63;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 创建失败";
    }
  }
&#63;>

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Getting started example of using mkdir in php to create a multi-level directory
  • Analysis of usage examples of mkdir function in php
  • mkdir in php The () function creates a folder with a safer permission setting method
  • Solution to the problem of PHP mkdir() without write permission
  • Unlink(), mkdir(), rmdir() and other methods in PHP Introduction to the use
  • PHP mkdir() definition and usage

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084566.htmlTechArticleHow PHP uses mkdir to create a multi-level directory. This article describes how PHP uses mkdir to create a multi-level directory. Share it with everyone for your reference, the details are as follows: Using mkdir() in PHP can...
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