PHP mkdir() function with example

PHP mkdir() function: Here, we will find out about the PHP mkdir() function with its syntax, parameters, returns type, and example.

PHP mkdir() function

The full type of mkdir is “Make Directory“, the function mkdir() is utilized to make an index.


mkdir(dir_path, access_mode, recursive, setting); 


  • dir_path – It characterizes the way to the registry, where we need to make an index.
  • access_mode – It is a discretionary parameter; its default value is 0777 that represents the vastest conceivable access. There are 4 values to be set for the entrance mode,
    • The principal value ought to be 0
    • The subsequent value sets the consent for the proprietor
    • The third value sets the consent for the proprietor’s client gathering
    • The fourth value sets the consent for every other person
    • The values are 1 for executing consent, 2 for composing authorization, 4 for understanding consent, we can add values to set the particular authorizations, for example, 1+2+4 = 7 = authorization for executing, compose and read.
  • Note: The access_mode parameter is overlooked on the Windows framework.
  • recursive – It is likewise a discretionary parameter; It characterizes the recursive mode.
  • setting – It is likewise a discretionary parameter; It sets the specific situation (a lot of alternatives that can change the conduct of a surge) of the document taking care of.

Return value:

It restores a Boolean value, “Genuine” – if the registry makes effectively or “False” – if the index doesn’t make.

Example: PHP code to make the catalog


//creating the directory
$ret_value = mkdir("/home/folder1");

if ($ret_value == true)
    echo "directory created successfully...";
    echo "directory is not created successfully...";



directory created successfully...

Leave a Comment

error: Alert: Content is protected!!