Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP mkdir() Function

PHP mkdir() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The mkdir() function creates a directory.

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 the permissions. Default is 0777 (allows global access).

The mode parameter consists of four digits:

  • The first digit is usually 0
  • The second digit specifies the owner's permissions
  • The third digit specifies the permissions of the owner's user group
  • The fourth digit specifies the permissions for everyone else
  • Possible values (to set multiple permissions, add the numbers below together):

    | | recursive | Optional. Specifies whether to set recursive mode. (Added in PHP 5) | | context | Optional. Specifies the context of the file handle. A context is a set of options that can modify the behavior of a stream. (Added in PHP 5) |

    Tips and Notes

    **Note:** The mode parameter is ignored on Windows platforms.


    Example


    PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual