<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.umask.php',
    1 => 'umask',
    2 => '改变当前的 umask',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => '文件系统函数',
  ),
  'prev' => 
  array (
    0 => 'function.touch.php',
    1 => 'touch',
  ),
  'next' => 
  array (
    0 => 'function.unlink.php',
    1 => 'unlink',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/filesystem/functions/umask.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.umask" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">umask</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">umask</span> &mdash; <span class="dc-title">改变当前的 umask</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.umask-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>umask</strong></span>(<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.integer.php" class="type int">int</a></span></span> <code class="parameter">$mask</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
 <span class="function"><strong>umask()</strong></span> 将 PHP 的 umask 设定为
   <code class="parameter">mask</code> &amp; 0777 并返回原来的
   umask。当 PHP 被作为服务器模块使用时，在每个请求结束后 umask
   会被恢复。
  </p>
 </div>

 
  <div class="refsect1 parameters" id="refsect1-function.umask-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">mask</code></dt>
     <dd>
      <p class="para">
       The new umask.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
  <div class="refsect1 returnvalues" id="refsect1-function.umask-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">mask</code> 为 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>，<span class="function"><strong>umask()</strong></span> 仅返回当前的 umask，有参数则返回原来的 umask。
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.umask-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">mask</code> 现在可以为 null。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.umask-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>umask()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$old </span><span style="color: #007700">= </span><span style="color: #0000BB">umask</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/path/some_dir/some_file.txt"</span><span style="color: #007700">, </span><span style="color: #0000BB">0755</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">umask</span><span style="color: #007700">(</span><span style="color: #0000BB">$old</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Checking<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$old </span><span style="color: #007700">!= </span><span style="color: #0000BB">umask</span><span style="color: #007700">()) {<br />    die(</span><span style="color: #DD0000">'An error occurred while changing back the umask'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


  <div class="refsect1 notes" id="refsect1-function.umask-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    在多线程的服务器上尽量避免使用这个函数。创建文件后要改变其权限最好还是使用
    <span class="function"><a href="function.chmod.php" class="function">chmod()</a></span>。使用 <span class="function"><strong>umask()</strong></span>
    会导致并发程序和服务器发生不可预知的情况，因为它们是使用相同的 umask 的。
   </p>
  </p></blockquote>
 </div>

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