mkdir() function in PHP


The mkdir() function is used to create a new directory.

Syntax

mkdir(file_path,mode,recursive,context)

Parameters

  • file_path − Path of the directory you want to create.

  • mode − Specify permission.

Set the mode with the following four values.

  • zero
  • permission for owner
  • permission for the owner’s user group
  • permissions for rest

The following are the values to set multiple permissions. You need to add the following numbers −

  • 1 = execute permissions
  • 2 = write permissions
  • 4 = read permissions
  • recursive − Set recursive mode

  • context − The context of the file handle.

Return

The mkdir() function returns TRUE on success and FALSE on failure.

The following is an example that creates a new directory. This sets the default mode 0777.

Example

<?php
   mkdir("testing");
?>

The above code creates a directory “testing.

Let us see another example that creates a new directory and sets the mode as well.

Example

<?php
   mkdir("QA", 0700);
?>

Updated on: 24-Jun-2020

175 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements