Home  >  Article  >  Backend Development  >  What does mkdir mean in php

What does mkdir mean in php

青灯夜游
青灯夜游Original
2022-02-09 18:13:353690browse

In PHP, mkdir means "create directory" and is a built-in function for creating a new directory. The syntax is "mkdir($path,$mode,$recursive,$context)"; if Returns TRUE if the directory is successfully created, and FALSE if it fails.

What does mkdir mean in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

What does mkdir mean in php

What does mkdir mean in php

mkdir is a built-in function in PHP for creating new directories.

Sometimes we need to create a directory on the server. For example, create a directory named after today's date to back up data, or create a directory named after the registered user name to store user registration information files, etc. In PHP, you can use the mkdir() function to create a new directory. The syntax format of the function is as follows:

mkdir($pathname, $mode, $recursive,$context)

The parameter description is as follows:

  • $pathname: To create directory path (including the name of the new directory);

  • $mode: optional parameter, used to set the permissions of the directory, consisting of four arrays, the default is 0777 (the largest access permissions), but $mode will be ignored under Windows;

  • $recursive: Optional parameter, when true, allows recursive creation of multi-level nested directories specified by $pathname , the default is false;

  • $context: Support for context (Context) has been added in PHP 5.0.0.

The meaning of the four numbers that make up the $mode parameter is as follows:

  • The first number is usually 0;

  • The second number specifies the permissions of the owner;

  • The third number specifies the permissions of the user group to which the owner belongs;

  • The fourth number specifies everyone else's permissions.

$mode parameter, except for the first number, the value range of the other three numbers is as follows (if you need to set multiple permissions, you can add the numbers of the corresponding permissions) :

  • 1 => Execute permission;

  • ##2 => Write permission;

  • 4 => Read permission.

Use the mkdir() function to create a new directory.

<?php
    $dir = &#39;./test/ttt&#39;;
    if(is_dir($dir)){
        echo "该目录以存在!";
    }else{
        if(mkdir($dir,0777,true)) echo &#39;目录创建成功!&#39;;
    }
?>

Run the above code to create a directory named test in the current directory, and create a directory named ttt in the test directory.

It should be noted that when using the mkdir() function to create a directory, the directory name cannot be the same as an existing directory name. If the same directory name appears, the program will report an error, as shown below:

Warning: mkdir(): File exists in D:\WWW\index.php on line 6

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What does mkdir mean in php. For more information, please follow other related articles on 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