PHP get current directory and relative directory method _php tutorial

Source: Internet
Author: User
How PHP Gets the current directory and relative directories

There are many ways to get a directory in PHP, and here's how to get the current directory and relative directory using PHP to avoid confusing it.

<?php//gets the directory where the current file is located, if a.php include b.php no matter which file it is written in, it represents the directory where the a.php file is located echo Realpath ('. '), '; Echo getcwd (), ';// Gets the parent directory of the current file, if a.php include b.php, regardless of which file is written, represents the parent directory of the directory where the a.php file is located, Echo Realpath ('.. '), ';//Gets the Web site root directory, All files are retrieved in the directory where the current project is located echo $_server[' Document_root ', ';//get directory information $path_parts = PathInfo (__file__); Echo ' DirName: ', $ path_parts[' dirname ', ';//represents the directory where the code resides, if a.php include b.php and this code snippet is written in b.php, then get the directory where the b.php file is located echo ' basename: ', $ path_parts[' basename ', ';//Ibid, gets the file name of the file where the code resides, such as: Inc.phpecho $path _parts[' extension ', ';//Ibid., gets the suffix of the file where the code resides , such as: Phpecho dirname (__file__), ';//effect with $path _parts[' dirname ']
  • 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.