<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.mkdir.php',
    1 => 'mkdir',
    2 => 'Makes directory',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Filesystem Functions',
  ),
  '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' => 'en',
    '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">Makes directory</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mkdir-description">
  <h3 class="title">Description</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">
   Attempts to create the directory specified by <code class="parameter">directory</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mkdir-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">directory</code></dt>
     <dd>
      <p class="para">
       The directory path.
       <div class="tip"><strong class="tip">Tip</strong><p class="simpara">A URL can be used as a
filename with this function if the <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> have been enabled.
See <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> for more details on how to specify the
filename. See the <a href="wrappers.php" class="xref">Supported Protocols and Wrappers</a> for links to information
about what abilities the various wrappers have, notes on their usage,
and information on any predefined variables they may
provide.</p></div>
      </p>
     </dd>
    
    
     <dt><code class="parameter">permissions</code></dt>
     <dd>
      <p class="para">
       The permissions are 0777 by default, which means the widest possible
       access. For more information on permissions, read the details
       on the <span class="function"><a href="function.chmod.php" class="function">chmod()</a></span> page.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        <code class="parameter">permissions</code> is ignored on Windows.
       </p>
      </p></blockquote>
      <p class="para">
       Note that you probably want to specify the <code class="parameter">permissions</code> as an octal number,
       which means it should have a leading zero. The <code class="parameter">permissions</code> is also modified
       by the current umask, which you can change using
       <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">
       If <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, then any parent directories to the <code class="parameter">directory</code> specified will
       also be created, with the same permissions.
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">A <a href="stream.contexts.php" class="link">context stream</a>
<span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mkdir-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    If the directory to be created already exists, that is considered an error
    and <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> will still be returned.  Use <span class="function"><a href="function.is-dir.php" class="function">is_dir()</a></span> or
    <span class="function"><a href="function.file-exists.php" class="function">file_exists()</a></span> to check if the directory already exists
    before trying to create it.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.mkdir-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Emits an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> level error if the directory
   already exists.
  </p>
  <p class="para">
   Emits an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> level error if the relevant
   permissions prevent creating the directory.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mkdir-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>mkdir()</strong></span> example</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>Example #2 <span class="function"><strong>mkdir()</strong></span> using the <code class="parameter">recursive</code> parameter</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">// Desired directory structure<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">// To create the nested structure, the $recursive parameter <br />// to mkdir() must be specified.<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">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.is-dir.php" class="function" rel="rdfs-seeAlso">is_dir()</a> - Tells whether the filename is a directory</span></li>    
    <li><span class="function"><a href="function.rmdir.php" class="function" rel="rdfs-seeAlso">rmdir()</a> - Removes directory</span></li>
    <li><span class="function"><a href="function.umask.php" class="function" rel="rdfs-seeAlso">umask()</a> - Changes the current umask</span></li>
   </ul>
  </p>
 </div>


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