How to Create Directory in Drupal 8 and Drupal 9

Drupal 8

function drupal_mkdir

drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL)

Creates a directory, optionally creating missing components in the path to the directory.

Code

function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {

  return \Drupal::service('file_system')->mkdir($uri, $mode, $recursive, $context);
}

Deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystem::mkdir().

Drupal 9

public function FileSystem::mkdir

public FileSystem::mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL)

Creates a directory, optionally creating missing components in the path to the directory.

When PHP's mkdir() creates a directory, the requested mode is affected by the process's umask. This function overrides the umask and sets the mode explicitly for all directory components created.

@todo Update with open_basedir compatible recursion logic from \Drupal\Component\PhpStorage\FileStorage::ensureDirectory().

Parameters

string $uri: A URI or pathname.

int $mode: Mode given to created directories. Defaults to the directory mode configured in the Drupal installation. It must have a leading zero.

bool $recursive: Create directories recursively, defaults to FALSE. Cannot work with a mode which denies writing or execution to the owner of the process.

resource $context: Refer to http://php.net/manual/ref.stream.php

Return value

bool Boolean TRUE on success, or FALSE on failure.

Overrides FileSystemInterface::mkdir 

Drupal 7

function drupal_mkdir

Creates a directory, optionally creating missing components in the path to the directory.

When PHP's mkdir() creates a directory, the requested mode is affected by the process's umask. This function overrides the umask and sets the mode explicitly for all directory components created.

Parameters

$uri: A URI or pathname.

$mode: Mode given to created directories. Defaults to the directory mode configured in the Drupal installation. It must have a leading zero.

$recursive: Create directories recursively, defaults to FALSE. Cannot work with a mode which denies writing or execution to the owner of the process.

$context: Refer to http://php.net/manual/ref.stream.php

Return value

Boolean TRUE on success, or FALSE on failure.



No comments:

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...