uTools-Manuals/docs/php/realpath.html
2019-04-08 23:22:26 +08:00

175 lines
6.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>返回规范化的绝对路径名</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.realpath" class="refentry">
<div class="refnamediv">
<h1 class="refname">realpath</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</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">string</span> <code class="parameter">$path</code></span>
) : <span class="type">string</span></div>
<p class="para rdfs-comment">
<span class="function"><strong>realpath()</strong></span> 扩展所有的符号连接并且处理输入的
<code class="parameter">path</code> 中的 &#039;/./&#039;, &#039;/../&#039; 以及多余的 &#039;/&#039;
并返回规范化后的绝对路径名。返回的路径中没有符号连接,&#039;/./&#039;
&#039;/../&#039; 成分。
</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">Note</strong>:
<p class="para">
Whilst a path must be supplied, the value can be blank or <strong><code>NULL</code></strong>
In these cases, the value is interpreted as the current directory.
</p>
</p></blockquote>
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.realpath-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns the canonicalized absolute pathname on success. The resulting path
will have no symbolic link, &#039;/./&#039; or &#039;/../&#039; components.
</p>
<p class="para">
<span class="function"><strong>realpath()</strong></span> 失败时返回 <strong><code>FALSE</code></strong>,比如说文件不存在的话。
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
The running script must have executable permissions on all directories in
the hierarchy, otherwise <span class="function"><strong>realpath()</strong></span> will return
<strong><code>FALSE</code></strong>.
</p>
</p></blockquote>
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">
因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB
以上的文件,一些文件系统函数可能返回无法预期的结果 。</span></p></blockquote>
</div>
<div class="refsect1 changelog" id="refsect1-function.realpath-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.3.0</td>
<td>
在之前的版本中,在 *BSD
系统上,如果仅仅是 <code class="parameter">path</code> 不存在的话,<span class="function"><strong>realpath()</strong></span>
并不会像其它系统那样返回 <strong><code>FALSE</code></strong>
</td>
</tr>
<tr>
<td>5.0.0</td>
<td>
在此之前的版本中,如果 <code class="parameter">path</code> 传入了空或者
<strong><code>NULL</code></strong>,将导致 <span class="function"><strong>realpath()</strong></span> 返回脚本当前的目录。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.realpath-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2839">
<p><strong>Example #1 <span class="function"><strong>realpath()</strong></span> 例子</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><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&nbsp;</span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'./../../etc/passwd'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
/etc/passwd
</pre></div>
</div>
</div>
<div class="example" id="example-2840">
<p><strong>Example #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"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'/windows/system32'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
C:\WINDOWS\System32
</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 class="member"><span class="function"><a href="basename.html" class="function" rel="rdfs-seeAlso">basename()</a> - 返回路径中的文件名部分</span></li>
<li class="member"><span class="function"><a href="dirname.html" class="function" rel="rdfs-seeAlso">dirname()</a> - 返回路径中的目录部分</span></li>
<li class="member"><span class="function"><a href="pathinfo.html" class="function" rel="rdfs-seeAlso">pathinfo()</a> - 返回文件路径的信息</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>