php The definition and usage of chdir() function?
In PHP, the chdir() function changes the current directory. What does it mean? It means to get the current directory and change it to another directory. Originally, your current directory is the WWW/index directory. When using After calling the chdir() function, return to the current directory. You will find that the current directory is no longer the WWW/index directory. This article introduces the php chdir() function in detail, I hope it will be helpful to everyone.
php chdir() function syntax
chdir(directory);
Parameter details:
The parameter directory is specified as new Current directory.
php The return value of the chdir() function
php The chdir() functionreturns TRUE if successful. On failure, FALSE is returned and an E_WARNING level error is thrown.
php chdir() function example
Use the php chdir() function to change the current directory. The code is as follows:
<?php // 获取当前目录 echo getcwd() . "<br>"; // 改变目录 var_dump(chdir("images")); echo "<br/>"; // 获得当前目录 echo getcwd(); ?>
Sample code explanation:
In the above example, we first use the getcwd() function to obtain the current directory and return the path name, then use the chdir() function explained in this article to change the current directory, and then return to the current directory.
Code browser operation output result:
[Related article recommendations]
php development How to achieve infinite directory traversal in
php method to read all file names in a directory and subdirectories
php method to modify the suffix of a specified file
The above is the detailed content of PHP changes the current directory function chdir () definition and usage examples detailed explanation. For more information, please follow other related articles on the PHP Chinese website!