<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.mkdir.php',
    1 => 'mkdir',
    2 => 'ディレクトリを作る',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'ファイルシステム 関数',
  ),
  'prev' => 
  array (
    0 => 'function.lstat.php',
    1 => 'lstat',
  ),
  'next' => 
  array (
    0 => 'function.move-uploaded-file.php',
    1 => 'move_uploaded_file',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/filesystem/functions/mkdir.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mkdir" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mkdir</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mkdir</span> &mdash; <span class="dc-title">ディレクトリを作る</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mkdir-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mkdir</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$directory</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$permissions</code><span class="initializer"> = 0777</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$recursive</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span></span> <code class="parameter">$context</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   <code class="parameter">directory</code> で指定したディレクトリを作成します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mkdir-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">directory</code></dt>
     <dd>
      <p class="para">
       ディレクトリのパス。
       <div class="tip"><strong class="tip">ヒント</strong><p class="simpara"><a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> が有効の場合、この関数のファイル名として
URL を使用することができます。ファイル名の指定方法に関する詳細は
<span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> を参照ください。
<a href="wrappers.php" class="xref">サポートするプロトコル/ラッパー</a> には、さまざまなラッパーの機能やその使用法、
提供される定義済み変数などの情報がまとめられています。</p></div>
      </p>
     </dd>
    
    
     <dt><code class="parameter">permissions</code></dt>
     <dd>
      <p class="para">
       パーミッションは 0777 がデフォルトです。
       これは最も緩やかなアクセス制限を意味します。
       パーミッションに関する詳細は <span class="function"><a href="function.chmod.php" class="function">chmod()</a></span> をご覧ください。
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        Windows では <code class="parameter">permissions</code> は無視されます。
       </p>
      </p></blockquote>
      <p class="para">
       <code class="parameter">permissions</code> を八進数で指定したくなることもあるかもしれません。
       その場合は先頭にゼロをつける必要があります。
       また <code class="parameter">permissions</code> は、
       現在設定されている umask の影響も受けます。
       umask を変更するには <span class="function"><a href="function.umask.php" class="function">umask()</a></span> を使用します。
      </p>
     </dd>
    
    
     <dt><code class="parameter">recursive</code></dt>
     <dd>
      <p class="para">
       <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を指定すると、
       <code class="parameter">directory</code>
       で指定されたディレクトリの、
       全ての親ディレクトリも同じパーミッションで作成されます。
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para"><a href="stream.contexts.php" class="link">ストリームコンテキスト</a>リソース</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mkdir-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   成功した場合に <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を、失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    作成しようとしたディレクトリが既に存在している場合、
    エラーとみなされ、<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> が返されます。
    作成しようとする前に、既にディレクトリが存在するかをチェックするには
    <span class="function"><a href="function.is-dir.php" class="function">is_dir()</a></span> や <span class="function"><a href="function.file-exists.php" class="function">file_exists()</a></span>
    を使ってください。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.mkdir-errors">
  <h3 class="title">エラー / 例外</h3>
  <p class="para">
   ディレクトリが既に存在する場合は <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> レベルのエラーが発生します。
  </p>
  <p class="para">
   ディレクトリの作成権限がない場合は <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> レベルのエラーが発生します。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mkdir-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>mkdir()</strong></span> の例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />mkdir</span><span style="color: #007700">(</span><span style="color: #DD0000">"/path/to/my/dir"</span><span style="color: #007700">, </span><span style="color: #0000BB">0700</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>例2 <span class="function"><strong>mkdir()</strong></span> での <code class="parameter">recursive</code> パラメータの使用例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// 作りたいディレクトリ構造<br /></span><span style="color: #0000BB">$structure </span><span style="color: #007700">= </span><span style="color: #DD0000">'./depth1/depth2/depth3/'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// 入れ子構造を作るには、$recursive パラメータを<br />// mkdir() に指定しなければなりません<br /><br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">mkdir</span><span style="color: #007700">(</span><span style="color: #0000BB">$structure</span><span style="color: #007700">, </span><span style="color: #0000BB">0777</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">)) {<br />    die(</span><span style="color: #DD0000">'Failed to create directories...'</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">// ...<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mkdir-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.rmdir.php" class="function" rel="rdfs-seeAlso">rmdir()</a> - ディレクトリを削除する</span></li>
    <li><span class="function"><a href="function.umask.php" class="function" rel="rdfs-seeAlso">umask()</a> - 現在の umask を変更する</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>