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

Source: Internet
Author: User
What is the definition and usage of the PHP chdir () function?

In PHP, the chdir () function is to change the current directory, what it means is to get the current directory, a directory, your current directory is the Www/index directory, when using the ChDir () function, and then return to the current directory, you will find that the current directory is not www/ Index of the directory. This article introduces the PHP chdir () function in detail, hoping to help you.

Syntax for PHP chdir () function

ChDir (directory);

Detailed parameters:

The parameters directory is the new current directory that is specified.

The return value of the PHP chdir () function

php chdir () function returns TRUE if successful. Failure returns false and throws an E_warning level error.

PHP chdir () Function Example

Use the PHP chdir () function to change the current directory with the following code:

<?php//gets the current directory echo GETCWD (). "<br>";//Change Directory Var_dump (chdir ("Images")); echo "<br/>";//Get current directory echo GETCWD (); >

The sample code explains:

In the above example, we first use the GETCWD () function, get to the current directory and return the pathname, then use the chdir () function explained in this article to change the current directory, and then return to the current directory.

The Code browser runs the output:

"Related articles recommended"

How to implement infinite traverse directory in PHP development

How PHP reads all filenames in directories and subdirectories

How PHP modifies the specified file suffix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.