PHP get current path or directory or file name

<?php

// Get the current file absolute path echo "__FILE__: ===>" .__ FILE__;   

echo '<br/>'; 

// Get the name of the current file

echo basename(__FILE__); echo '<br/>';  

  // Get the current script directory echo "__DIR__: ===>" .__ DIR__; 

echo '<br/>';    

// dirname returns the directory portion of the path,

dirname (__ FILE__) corresponds __DIR__ 

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

echo '<br/>';    

// $ _ SERVER [ 'PHP_SELF'] and $ _SERVER result [ 'SCRIPT_NAME'] is generally the same, they all get the file name of the current script 

// differentiated only when running in cgi php way when, but now almost can not find a way to run php to cgi 

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

echo '<br/>';    

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

echo '<br/>';    

// absolute path of the currently executing script. Remember, php is run in CLI mode of acquisition is less than 

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

echo '<br/>';    

// the document root directory of the current script is executing. Defined in the server configuration file. 

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

echo '<br>';    

// getcwd () returns the current working directory 

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

echo '<br>'; 

?>

Guess you like

Origin www.cnblogs.com/yyy6901/p/11126141.html