Latest web development tutorials

PHP chdir () function

PHP Directory PHP Directory Reference

Examples

Change the current 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

chdir () function to change the current directory.


grammar

chdir( directory );

参数 描述
directory 必需。规定新的当前目录。

technical details

return value: Success, returns TRUE. It failed to return FALSE, and throws E_WARNING level error.
PHP version: 4.0+


PHP Directory PHP Directory Reference