Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
communitycreator

What is chdir in PHP?

Sheza Naveed

Overview

Chdir is a PHP function that changes the current directory to the directory specified in an argument.

Syntax


chdir(string $directory): bool

Parameters

The function takes in one parameter, dir.

dir is the path to the new current directory.

Return value

The function returns a boolean value. It returns true if the directory is changed successfully. Otherwise, it returns false.

Code

<?php
// prints the value of current directory
echo getcwd() . "\n";

// changes the current directory to "edpresso"
chdir("edpresso");

// prints the value of new current directory
echo getcwd();
?> 

Output


/home/educative 
/home/educative/edpresso

RELATED TAGS

php
communitycreator
RELATED COURSES

View all Courses

Keep Exploring