Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

chdir()

Example

Change the current working directory.

<?php
// Get current directory
echo getcwd() . “<br>”;

// Change directory
chdir(“images”);

// Get current directory
echo getcwd();
?>

Result:

/home/php
/home/php/images

Definition and Usage

The chdir() function changes the current working directory.

Syntax

chdir(directory)

Parameter Values

Parameter

Description

directory

Required. Specifies the path to the new current directory.

Technical Details

 

Return Value:

Returns TRUE on success, FALSE on failure, and throws an E_WARNING level error on failure.

PHP Version:

4.0+