Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. System.php

function System::mkDir

Make directories.

The -p option will create parent directories

Parameters

string $args the name of the director(y|ies) to create:

Return value

bool True for success

1 call to System::mkDir()
System::mktemp in vendor/pear/pear-core-minimal/src/System.php
Creates temporary files or directories. This function will remove the created files when the scripts finish its execution.

File

vendor/pear/pear-core-minimal/src/System.php, line 254

Class

System
System offers cross platform compatible system functions

Code

public static function mkDir($args) {
    $opts = System::_parseArgs($args, 'pm:');
    if (PEAR::isError($opts)) {
        return System::raiseError($opts);
    }
    $mode = 0777;
    // default mode
    foreach ($opts[0] as $opt) {
        if ($opt[0] == 'p') {
            $create_parents = true;
        }
        elseif ($opt[0] == 'm') {
            // if the mode is clearly an octal number (starts with 0)
            // convert it to decimal
            if (strlen($opt[1]) && $opt[1][0] == '0') {
                $opt[1] = octdec($opt[1]);
            }
            else {
                // convert to int
                $opt[1] += 0;
            }
            $mode = $opt[1];
        }
    }
    $ret = true;
    if (isset($create_parents)) {
        foreach ($opts[1] as $dir) {
            $dirstack = array();
            while ((!file_exists($dir) || !is_dir($dir)) && $dir != DIRECTORY_SEPARATOR) {
                array_unshift($dirstack, $dir);
                $dir = dirname($dir);
            }
            while ($newdir = array_shift($dirstack)) {
                if (!is_writeable(dirname($newdir))) {
                    $ret = false;
                    break;
                }
                if (!mkdir($newdir, $mode)) {
                    $ret = false;
                }
            }
        }
    }
    else {
        foreach ($opts[1] as $dir) {
            if ((@file_exists($dir) || !is_dir($dir)) && !mkdir($dir, $mode)) {
                $ret = false;
            }
        }
    }
    return $ret;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal