php8.5
Home/ Manual/ dir / functions/ getcwd

getcwd

PHP function Edit on GitHub ✎

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

Gets the current working directory

Description

getcwd(): string|false

Gets the current working directory.

Parameters Parameters

Return Values

Returns the current working directory on success, or false on failure.

On some Unix variants, getcwd() will return false if any one of the parent directories does not have the readable or search mode set, even if the current directory does. See chmod() for more information on modes and permissions.

Examples

getcwd() example

php
<?php

// current directory
echo getcwd() . "\n";

chdir('cvs');

// current directory
echo getcwd() . "\n";

?>

The above example will output something similar to:

output
/home/didou
/home/didou/cvs

Notes

Caution

If the PHP interpreter has been built with ZTS (Zend Thread Safety) enabled, the current working directory returned by getcwd() may be different from that returned by operating system interfaces. External libraries (invoked through FFI) which depend on the current working directory will be affected.

See Also

Source: reference/dir/functions/getcwd.xml · from the official PHP manual (php/doc-en)