PHP chdir() function with example

PHP chdir() function: Here, we will find out about the PHP chdir() function with its syntax, parameters, returns a type, and example.

PHP chdir() function

The full type of chdir is “Change Directory“, the function chdir() is utilized to change the present working registry.

Syntax:

mkdir(directory); 

Parameter(s):

  • index – It characterizes the new catalog.

Return value:

It restores a Boolean value, “Genuine” – if index changes effectively or “False” – if the catalogue doesn’t change.

Example: PHP code to change the catalogue

<?php
//getting & printing current working directory
$result = getcwd();
echo "current working directory is: ".$result."<br/>";

//changing the directory
chdir("/home/folder1");

//after changing the directory....
//getting & printing current working directory
$result = getcwd();
echo "current working directory is: ".$result."<br/>";
?>

Output

current working directory is: /home
current working directory is: /home/folder1

Leave a Comment

error: Alert: Content is protected!!