PHP chdir() Function

Example

Change the current directory:

<?php
// Get the current directory
echo getcwd() . "<br>";
// Change directory
chdir("images");
// Get the current directory
echo getcwd();
?>

Result:

/home/php
/home/php/images

Definition and Usage

The chdir() function changes the current directory.

Syntax

chdir(directory);
Parameter Description
directory Required. Specifies a new current directory.

Technical Details

Return Value: Returns TRUE on success. Returns FALSE on failure, and throws an E_WARNING level error.
PHP Version: 4.0+