PHP mkdir()Functions


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual

Definition and Usage

The mkdir() function creates a directory.

This function returns TRUE on success, or FALSE on failure.

Syntax

mkdir(path,mode,recursive,context)

Parameters Description
path Required. Specifies the name of the directory to create.
mode Optional. Specifies permissions. Default is 0777 (allows global access).

The mode parameter consists of four numbers:

  • The first number is usually 0
  • The second number specifies the owner's permissions
  • The third number specifies the permissions of the owner's user group
  • The fourth number specifies the permissions for everyone else

Possible values (to set multiple permissions, add the numbers below together):

  • 1 = execute permissions
  • 2 = write permissions
  • 4 = read permissions
recursive Optional. Specifies whether to set recursive mode. (Added in PHP 5)
context Optional. Specifies the environment of the file handle. context is a set of options that can modify the behavior of the stream. (Added in PHP 5)


Tips and Notes

Note:The mode parameter is ignored on Windows platforms.


Examples

<?php
mkdir("testing");
?>


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual Other Extensions