What is chdir in PHP?
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.
diris 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 directoryecho getcwd() . "\n";// changes the current directory to "edpresso"chdir("edpresso");// prints the value of new current directoryecho getcwd();?>
Output
/home/educative
/home/educative/edpresso