update : 2015.11.03
php.shukuma.com

검색:
 
 
Makes directory

mkdir

(PHP 4, PHP 5, PHP 7)

mkdirMakes directory

설명

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

Attempts to create the directory specified by pathname.

인수

pathname

The directory path.

mode

The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page.

Note:

mode is ignored on Windows.

Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().

recursive

Allows the creation of nested directories specified in the pathname.

context

Note: Context 지원은 PHP 5.0.0에서 추가되었습니다. contexts에 관한 자세한 설명은 Streams을 참고하십시오.

반환값

성공 시 TRUE를, 실패 시 FALSE를 반환합니다.

예제

Example #1 mkdir() example

<?php
mkdir
("/path/to/my/dir"0700);
?>

Example #2 mkdir() using the recursive parameter

<?php
// Desired folder structure
$structure './depth1/depth2/depth3/';

// To create the nested structure, the $recursive parameter 
// to mkdir() must be specified.

if (!mkdir($structure0777true)) {
    die(
'Failed to create folders...');
}

// ...
?>

오류/예외

Emits an E_WARNING level error if the directory already exists.

Emits an E_WARNING level error if the relevant permissions prevent creating the directory.

주의

Note: 안전 모드를 활성화했을 경우, PHP는 작업하려는 디렉토리가 실행중인 스크립트와 같은 UID(owner)를 가지고 있는지 확인합니다.

참고

  • is_dir() - Tells whether the filename is a directory
  • rmdir() - Removes directory