English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP chdir() Function Usage and Example

PHP Directory Reference Manual

The chdir() function is used to change the current directory.

Syntax

bool chdir ( string $directory )

Definition and Usage

It changes the current directory of PHP to the directory passed.

Parameter

NumberParameters and Description
1

directory(Required)

Changes the current directory of PHP to directory.

Return value

Returns TRUE on success, FALSE on failure.

Online Example

Here is the usage of this function, changing the current directory:

<?php
   echo getcwd() . "\n";
   chdir('html');
   echo getcwd() . "\n";
?>
Test and see‹/›

Output result:

/home/w3codebox
/home/w3codebox/html