lib/blobfolio/common/file.php
public static function mkdir(string $path, $chmod=null) {
		// Figure out a good default CHMOD.
		if (! $chmod || ! \is_numeric($chmod)) {
			$chmod = (\fileperms(__DIR__) & 0777 | 0755);
		}

		// Sanitize the path.
		ref\file::path($path, false);
		if (! $path || (false !== \strpos($path, '://'))) {
			return false;
		}

		// We only need to proceed if the path doesn't exist.
		if (! @\is_dir($path)) {
			ref\file::untrailingslash($path);

			// Figure out where we need to begin.
			$base = \dirname($path);
			while ($base && ('.' !== $base) && ! @\is_dir($base)) {
				$base = \dirname($base);
			}

			// Make it.
			if (! @\mkdir($path, 0777, true)) {
				return false;
			}

			// Fix permissions.
			if ($path !== $base) {
				// If we fell deep enough that base became relative,
				// let's move it back.
				if (! $base || ('.' === $base)) {
					$base = __DIR__;
				}

				// Base should be inside path. If not, something weird
				// has happened.
				if (0 !== mb::strpos($path, $base)) {
					return true;
				}

				$path = mb::substr($path, mb::strlen($base), null);
				ref\file::unleadingslash($path);
				$parts = \explode('/', $path);
				$path = $base;

				// Loop through each subdirectory to set the appropriate
				// permissions.
				foreach ($parts as $v) {
					$path .= ('/' === \substr($path, -1)) ? $v : "/$v";
					if (! @\chmod($path, $chmod)) {
						return true;
					}
				}
			}
			else {
				@\chmod($path, $chmod);
			}
		}

		return true;
	}
public static function mkdir(string $path, $chmod=null) {
		// Figure out a good default CHMOD.
		if (! $chmod || ! \is_numeric($chmod)) {
			$chmod = (\fileperms(__DIR__) & 0777 | 0755);
		}

		// Sanitize the path.
		ref\file::path($path, false);
		if (! $path || (false !== \strpos($path, '://'))) {
			return false;
		}

		// We only need to proceed if the path doesn't exist.
		if (! @\is_dir($path)) {
			ref\file::untrailingslash($path);

			// Figure out where we need to begin.
			$base = \dirname($path);
			while ($base && ('.' !== $base) && ! @\is_dir($base)) {
				$base = \dirname($base);
			}

			// Make it.
			if (! @\mkdir($path, 0777, true)) {
				return false;
			}

			// Fix permissions.
			if ($path !== $base) {
				// If we fell deep enough that base became relative,
				// let's move it back.
				if (! $base || ('.' === $base)) {
					$base = __DIR__;
				}

				// Base should be inside path. If not, something weird
				// has happened.
				if (0 !== mb::strpos($path, $base)) {
					return true;
				}

				$path = mb::substr($path, mb::strlen($base), null);
				ref\file::unleadingslash($path);
				$parts = \explode('/', $path);
				$path = $base;

				// Loop through each subdirectory to set the appropriate
				// permissions.
				foreach ($parts as $v) {
					$path .= ('/' === \substr($path, -1)) ? $v : "/$v";
					if (! @\chmod($path, $chmod)) {
						return true;
					}
				}
			}
			else {
				@\chmod($path, $chmod);
			}
		}

		return true;
	}
public static function mkdir ( string $ path , $ chmod = null ) { // Figure out a good default CHMOD. if ( ! $ chmod || ! \ is_numeric ( $ chmod ) ) { $ chmod = ( \ fileperms ( __DIR__ ) & 0777 | 0755 ) ; } // Sanitize the path. ref \ file :: path ( $ path , false ) ; if ( ! $ path || ( false !== \ strpos ( $ path , '://' ) ) ) { return false ; } // We only need to proceed if the path doesn't exist. if ( ! @ \ is_dir ( $ path ) ) { ref \ file :: untrailingslash ( $ path ) ; // Figure out where we need to begin. $ base = \ dirname ( $ path ) ; while ( $ base && ( '.' !== $ base ) && ! @ \ is_dir ( $ base ) ) { $ base = \ dirname ( $ base ) ; } // Make it. if ( ! @ \ mkdir ( $ path , 0777 , true ) ) { return false ; } // Fix permissions. if ( $ path !== $ base ) { // If we fell deep enough that base became relative, // let's move it back. if ( ! $ base || ( '.' === $ base ) ) { $ base = __DIR__ ; } // Base should be inside path. If not, something weird // has happened. if ( 0 !== mb :: strpos ( $ path , $ base ) ) { return true ; } $ path = mb :: substr ( $ path , mb :: strlen ( $ base ) , null ) ; ref \ file :: unleadingslash ( $ path ) ; $ parts = \ explode ( '/' , $ path ) ; $ path = $ base ; // Loop through each subdirectory to set the appropriate // permissions. foreach ( $ parts as $ v ) { $ path .= ( '/' === \ substr ( $ path , - 1 ) ) ? $ v : "/$v" ; if ( ! @ \ chmod ( $ path , $ chmod ) ) { return true ; } } } else { @ \ chmod ( $ path , $ chmod ) ; } } return true ; }
Resursively Make Directory

PHP's mkdir function can be recursive, but the permissions are
only set correctly on the innermost folder created.

@param string $path Path.
@param int $chmod CHMOD.
@return bool True/false.
Resursively Make Directory