Home > Backend Development > PHP Tutorial > Get the absolute path of the file containing the code of the upper-level directory

Get the absolute path of the file containing the code of the upper-level directory

WBOY
Release: 2016-07-25 09:05:56
Original
1150 people have browsed it
  1. echo __FILE__ ; // Get the absolute address of the current file, result: F:wwwtest.php
  2. echo dirname(__FILE__); // Get the absolute directory where the current file is, result: F: www
  3. echo dirname(dirname(__FILE__)); //Get the upper directory name of the current file, result: F:
  4. ?>
Copy code

By the way, here is another function in PHP: chdir() function.

chdir() function Definition 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. Specifies the new current directory. Example:

  1. //Get the current directory

  2. echo getcwd();
  3. echo "
    ";

  4. // Change to the images directory

  5. chdir("images");
  6. echo "
    ";
  7. echo getcwd();
  8. ?>

Copy the code

Output: C:jbxue.commain C:jbxue.commainimages



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template