Home >Backend Development >PHP Tutorial >Flexible method of obtaining file path through __FILE__

Flexible method of obtaining file path through __FILE__

WBOY
WBOYOriginal
2016-07-25 09:05:491107browse
  1. // Get the current path of the file + file name
  2. echo __FILE__;
  3. echo '
    ';
  4. // Get the current path of the file
  5. echo dirname(__FILE__);
  6. echo '
    ';
  7. // Get the upper-level directory path of the file
  8. echo dirname(dirname(__FILE__));
  9. ?>
Copy the code

Run results: F:mysitewwwindex.php F:mysitewww F:mysite

Remarks: __FILE__, you can get the current path of the file, which will not change even if it is included. It can be used as the absolute path of the website on the server, and other directories will be distributed based on this.



Statement:
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