PHP chdir()Functions
PHP Directory Reference Manual
Examples
Change the current directory:
<?php
// Get current directory
echo getcwd() . "<br>";
// Change directory
chdir("images");
// Get current directory
echo getcwd();
?>
// Get current directory
echo getcwd() . "<br>";
// Change directory
chdir("images");
// Get current directory
echo getcwd();
?>
Result:
/home/php
/home/php/images
/home/php/images
Definition and Usage
The chdir() function changes the current directory.
Syntax
chdir(directory);
| Parameters | Description |
|---|---|
| directory | Required. Specifies the 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+ |
PHP Directory Reference Manual Other Extensions