php get the current directory and current folder

 

  1. <?php  

  2. /**

  3. * PHP access path or directory implementation

  4. */  

  5.  

  6. //Magic variable, get the absolute path of the current file  

  7. echo "__FILE__:  ========>  ".__FILE__;

  8. echo '<br/>';

  9.  
  10. //Magic variable, get the directory of the current script

  11. echo "__DIR__: ========>" .__ DIR__;

  12. echo '<br/>';

  13.  
  14. //dirname returns the directory part of the path, dirname(__FILE__) is equivalent to __DIR__

  15. echo "dirname(__FILE__):  ========>  ".dirname(__FILE__);

  16. echo '<br/>';

  17.  
  18. //$_SERVER['PHP_SELF'] and $_SERVER['SCRIPT_NAME'] generally have the same result, they both get the file name of the current script

  19. //There is a difference only when php runs in cgi mode, but now it is almost impossible to run php in cgi mode

  20. echo '$_SERVER["PHP_SELF"]:  ========>  '.$_SERVER['PHP_SELF'];

  21. echo '<br/>';

  22.  
  23. echo '$_SERVER["SCRIPT_NAME"]:  ========>  '.$_SERVER['SCRIPT_NAME'];

  24. echo '<br/>';

  25.  
  26. //The absolute path of the currently executing script. Remember, it is not available to run php in CLI mode

  27. echo '$_SERVER["SCRIPT_FILENAME"]:  ========>  '.$_SERVER['SCRIPT_FILENAME'];

  28. echo '<br/>';

  29.  
  30. //The document root directory where the currently running script is located. Defined in the server configuration file.

  31. echo '$_SERVER["DOCUMENT_ROOT"]:  ========>  '.$_SERVER['DOCUMENT_ROOT'];

  32. echo '<br>';

  33.  
  34. //getcwd() returns the current working directory

  35. echo "getcwd():  ========>  ".getcwd();

  36. echo '<br>';

  37.  
  38. echo '<br>';

  39. echo "PHP Finishing";

 

 

Guess you like

Origin blog.csdn.net/zl17822307869/article/details/113825560