PHP Function Reference

PHP getcwd() Function



The PHP getcwd() function returns the current working directory.

Syntax

getcwd()

Parameters

No parameter is required.

Return Value

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

Example:

The example below shows the usage of getcwd() function.

<?php
//getting current directory
echo getcwd()."\n";

//changing the current directory
getcwd('temp');

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

The output of the above code will be:

/home/html
/home/html/temp

❮ PHP Directory Reference