PHP get the file Absolute path code (previous level directory) _php tips

Source: Internet
Author: User
PHP Get file absolute path
Copy Code code as follows:

<?php
Echo __file__; Get the absolute address of the current file, result: D:\www\test.php
echo dirname (__file__); Gets the absolute directory where the current file is located, as a result: D:\www\
Echo dirname (DirName (__file__)); Gets the top level directory name of the current file, as a result: d:\
?>


ChDir () function
Definitions and usage
The ChDir () function changes the current directory to the specified directory.

If successful, the function returns True, otherwise it returns false.

Grammar
ChDir (directory) parameter description
Directory required. Specify a new current directory.
Example
Copy Code code as follows:

<?php
Get current directory
Echo GETCWD ();
echo "<br/>";

Change to images Directory
ChDir ("Images");
echo "<br/>";
Echo GETCWD ();
?>

Output:

C:\testweb\main
C:\testweb\main\images

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.