PHP get the current directory and Relative directory method summary

Source: Internet
Author: User
There are many ways to get a directory in PHP, and here's how to get the current directory and relative directory using PHP.

 
 '; Echo getcwd (), '
';//Gets the parent directory of the current file, if a.php include b.php, regardless of which file is written, is the parent directory that represents the directory where the a.php file is located, Echo Realpath ('.. '), '
'///Get the root directory of the website, all the files are 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 '], '
'///indicates 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 is located, for example: Inc.phpecho $path _parts[' extension '], '
';//Ibid., gets the suffix name of the file where the code is located, for example: Phpecho dirname (__file__), '
';//effect with $path _parts[' dirname ')
  • Related Article

    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.