Home >Backend Development >PHP Problem >How to change the current directory in php
php method to change the current directory: first create a PHP sample file; then obtain the current directory through the getcwd function; finally use the "chdir("images");" method to change the directory.
Recommended: "PHP Video Tutorial"
php chdir function changes the current directory
Example
Change the current directory:
<?php // 获取当前目录 echo getcwd() . "<br>"; // 改变目录 chdir("images"); // 获得当前目录 echo getcwd(); ?>
Result:
/home/php /home/php/images
Definition and usage
chdir( ) function changes the current directory.
Syntax
chdir(directory);
Parameters
directory required. Specifies the new current directory.
The above is the detailed content of How to change the current directory in php. For more information, please follow other related articles on the PHP Chinese website!