array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.getcwd.php', 1 => 'getcwd', ), 'up' => array ( 0 => 'ref.dir.php', 1 => '目录函数函数', ), 'prev' => array ( 0 => 'function.dir.php', 1 => 'dir', ), 'next' => array ( 0 => 'function.opendir.php', 1 => 'opendir', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/dir/functions/getcwd.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
getcwd — 取得当前工作目录
此函数没有参数。
成功则返回当前工作目录,失败返回 false
。
在某些 Unix 的变种下,如果任何父目录没有设定可读或搜索模式,即使当前目录设定了,getcwd()
还是会返回 false
。有关模式与权限的更多信息见 chmod()。
示例 #1 getcwd() 例子
<?php
// 当前目录
echo getcwd() . "\n";
chdir('cvs');
// 当前目录
echo getcwd() . "\n";
?>
以上示例的输出类似于:
/home/didou /home/didou/cvs
如果是启用 ZTS(Zend 线程安全)构建的 PHP 解释器,则 getcwd() 返回的当前工作目录可能与操作系统接口返回的不同。当前工作目录的外部库依赖(通过 FFI 调用)可能会受到影响。