How to create a new folder / directory in php ?

In php we uses mkdir() function to create a new folder

SYNTAX

mkdir(path,mode,recursive,context)

path : Required. Specifies the name of the directory to create

create new folder in php

create new folder in php

mode : Optional. Specifies permissions. By default, the mode is 0777 (widest possible access).

recursive : Optional. Specifies if the recursive mode is set (added in PHP 5)

context Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream (added in PHP 5)

Example Codes

1) This will create a folder named 9t9 in where the php file located

<?php
mkdir("./9t9/", 0777);
?>

2) This will create a folder named 2013 under the new folder year

<?php
// Desired folder structure
$structure = './year/2013';

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

if (!mkdir($structure, 0, true)) {
    die('Failed to create folders...');
}

// ...
?>