How to Create a Folder/Directory using php

We can create a folder with the help of mkdir already defined function

We can use tis function like this


bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )



The directory path.


The mode is used to define accessibility of the folder


Allows the creation of nested directories specified in the pathname. Defaults to FALSE.

Return Values:

Returns TRUE on success or FALSE on failure.

Example 1:

mkdir(“/path/to/my-dir”, 0777);

Example 2:

// Desired folder structure
$dir = ‘/path/to/my-dir’;

// To create the nested structure, the $recursive parameter
// to mkdir() must be specified.

if (!mkdir($dir, 0, true)) {
die(‘Failed to create folders…’);

Bansal Sumit

To seek challenging roles and to achieve excellence in the field of Open Source Web Technology with a profound spirit of commitment and dedication.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *