Home >Backend Development >PHP Tutorial >PHP changes the current directory function chdir () definition and usage examples detailed explanation

PHP changes the current directory function chdir () definition and usage examples detailed explanation

怪我咯
怪我咯Original
2017-06-09 11:36:243118browse

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:

PHP changes the current directory function chdir () definition and usage examples detailed explanation

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn