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

Flexible method of obtaining file path through __FILE__

WBOY
Release: 2016-07-25 09:05:49
Original
1087 people have browsed it
  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.



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