getcwd

(PHP 4, PHP 5, PHP 7, PHP 8)

getcwd取得当前工作目录

说明

getcwd(): string|false

取得当前工作目录。

参数

此函数没有参数。

返回值

成功则返回当前工作目录,失败返回 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 调用)可能会受到影响。

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top