<?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.file-exists.php',
    1 => 'file_exists',
    2 => '检查文件或目录是否存在',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => '文件系统函数',
  ),
  'prev' => 
  array (
    0 => 'function.file.php',
    1 => 'file',
  ),
  'next' => 
  array (
    0 => 'function.file-get-contents.php',
    1 => 'file_get_contents',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/filesystem/functions/file-exists.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.file-exists" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">file_exists</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">file_exists</span> &mdash; <span class="dc-title">检查文件或目录是否存在</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.file-exists-description">
  <h3 class="title">说明</h3>
 <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>file_exists</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

    <p class="para rdfs-comment">
     检查文件或目录是否存在。
    </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.file-exists-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       文件或目录的路径。
      </p>
      <p class="para">
       在 Windows 中要用 <var class="filename">//computername/share/filename</var> 或者
   <var class="filename">\\computername\share\filename</var> 来检查网络中的共享文件。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.file-exists-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果由 <code class="parameter">filename</code> 指定的文件或目录存在则返回
   <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>。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    The check is done using the real UID/GID instead of the effective one.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">
因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型，对 2GB
以上的文件，一些文件系统函数可能返回无法预期的结果。</span></p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.file-exists-errors">
  <h3 class="title">错误／异常</h3>
  <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.file-exists-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 测试一个文件是否存在</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$filename </span><span style="color: #007700">= </span><span style="color: #DD0000">'/path/to/foo.txt'</span><span style="color: #007700">;<br /><br />if (</span><span style="color: #0000BB">file_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"The file </span><span style="color: #0000BB">$filename</span><span style="color: #DD0000"> exists"</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"The file </span><span style="color: #0000BB">$filename</span><span style="color: #DD0000"> does not exist"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 errors" id="refsect1-function.file-exists-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
失败时抛出 <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> 警告。
</p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.file-exists-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.is-readable.php" class="function" rel="rdfs-seeAlso">is_readable()</a> - 判断给定文件名是否可读</span></li>
    <li><span class="function"><a href="function.is-writable.php" class="function" rel="rdfs-seeAlso">is_writable()</a> - 判断给定的文件名是否可写</span></li>
    <li><span class="function"><a href="function.is-file.php" class="function" rel="rdfs-seeAlso">is_file()</a> - 判断给定文件名是否为一个正常的文件</span></li>
    <li><span class="function"><a href="function.file.php" class="function" rel="rdfs-seeAlso">file()</a> - 把整个文件读入一个数组中</span></li>
    <li><span class="classname"><a href="class.splfileinfo.php" class="classname">SplFileInfo</a></span></li>
   </ul>
  </p>
 </div>

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