Home  >  Article  >  Backend Development  >  How to change the current directory in php

How to change the current directory in php

藏色散人
藏色散人Original
2020-08-21 09:59:392454browse

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.

How to change the current directory in php

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!

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