PHP Tutorial

PHP Examples

PHP Practice

PHP Directory chdir() Function (With Examples)

In this tutorial, we will learn about the PHP chdir() function with its usage, syntax, parameters, return value, and examples. By IncludeHelp Last updated : December 31, 2023

PHP chdir() function

The full form of chdir is "Change Directory", the function chdir() is used to change the current working directory.

Syntax

The syntax of the chdir() function:

mkdir(directory);

Parameters

The parameters of the chdir() function:

  • directory – It defines the new directory.

Return Value

It returns a Boolean value, "TRUE" – if directory changes successfully or "FALSE" – if the directory does not change.

PHP chdir() Function Example

PHP code to change the directory.

<?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

The output of the above example is:

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

To understand the above example, you should have the basic knowledge of the following PHP topics:

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.