mkdir()
mkdir() — Makes directory.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Attempts to create the directory specified by directory.
Signature
mkdir(string $directory, int $permissions = 0777, bool $recursive = false, ?resource $context = null): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $directory | string | The directory path. TipA URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. |
| $permissions | int | The permissions are 0777 by default, which means the widest possible access. For more information on permissions, read the details on the chmod() page. |
| $recursive | bool | If true, then any parent directories to the directory specified will also be created, with the same permissions. |
| $context | ?resource | A context stream resource. |
Return value
Returns true on success or false on failure. Note: If the directory to be created already exists, that is considered an error and false will still be returned. Use is_dir() or file_exists() to check if the directory already exists before trying to create it. If the directory to be created already exists, that is considered an error and false will still be returned. Use is_dir() or file_exists() to check if the directory already exists before trying to create it.
Example
A runnable snippet:
mkdir("/path/to/my/dir", 0700);
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page mkdir() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.