<?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.realpath.php',
    1 => 'realpath',
    2 => '返回规范化的绝对路径名',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => '文件系统函数',
  ),
  'prev' => 
  array (
    0 => 'function.readlink.php',
    1 => 'readlink',
  ),
  'next' => 
  array (
    0 => 'function.realpath-cache-get.php',
    1 => 'realpath_cache_get',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/filesystem/functions/realpath.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.realpath" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">realpath</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">realpath</span> &mdash; <span class="dc-title">返回规范化的绝对路径名</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.realpath-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>realpath</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$path</code></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>realpath()</strong></span> 扩展所有符号连接，并处理输入
   <code class="parameter">path</code> 中的 <code class="literal">/./</code>、<code class="literal">/../</code> 和多余的
   <code class="literal">/</code>，并返回规范化的绝对路径名。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.realpath-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">path</code></dt>
     <dd>
      <p class="para">
       要处理的路径。
       <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
         虽然必须提供路径，但该值可以是一个空字符串。
         在这种情况下，该值将被解释为当前目录。
        </p>
       </p></blockquote>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.realpath-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回规范化的绝对路径名。返回的路径中没有符号连接（symbolic link）、<code class="literal">/./</code> 或 <code class="literal">/../</code> 成分。
   例如 <code class="literal">\</code> 和 <code class="literal">/</code> 这样的尾随分隔符也将被删除。
  </p>
  <p class="para">
   <span class="function"><strong>realpath()</strong></span> 失败时返回 <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">
    当前运行的脚本必须对要处理的路径中的每层目录都具有可执行权限，否则
    <span class="function"><strong>realpath()</strong></span> 将返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    对于不区分大小写的文件系统，<span class="function"><strong>realpath()</strong></span> 不一定会规范字符大小写。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    <span class="function"><strong>realpath()</strong></span> 函数不适用于 Phar 内的文件，因为该路径是虚拟路径，而不是真实路径。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    在 Windows 上，目录的结点和符号链接仅扩展一级。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">
因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型，对 2GB
以上的文件，一些文件系统函数可能返回无法预期的结果。</span></p></blockquote>
 </div>


 <div class="refsect1 examples" id="refsect1-function.realpath-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>realpath()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />chdir</span><span style="color: #007700">(</span><span style="color: #DD0000">'/var/www/'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'./../../etc/passwd'</span><span style="color: #007700">) . </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'/tmp/'</span><span style="color: #007700">) . </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">/etc/passwd
/tmp</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>示例 #2 Windows 上的 <span class="function"><strong>realpath()</strong></span></strong></p>
    <div class="example-contents"><p>
     在 Windows 上，<span class="function"><strong>realpath()</strong></span> 会将 unix 风格的路径改成 Windows 风格。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'/windows/system32'</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'C:\Program Files\\'</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">C:\WINDOWS\System32
C:\Program Files</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.realpath-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.basename.php" class="function" rel="rdfs-seeAlso">basename()</a> - 返回路径中的文件名部分</span></li>
    <li><span class="function"><a href="function.dirname.php" class="function" rel="rdfs-seeAlso">dirname()</a> - 返回路径中的目录部分</span></li>
    <li><span class="function"><a href="function.pathinfo.php" class="function" rel="rdfs-seeAlso">pathinfo()</a> - 返回文件路径的信息</span></li>
   </ul>
  </p>
 </div>


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