Difference between PHP $_SERVER['SCRIPT_FILENAME'] and __FILE__


$_SERVER['SCRIPT_FILENAME'] -------> The absolute path and file name of the currently executing program
__FILE__ -------> The absolute path and file name of the original file (included file)


eg:
Assuming that the web root directory is e:/myweb
, first create e:/myweb/index.php and the
content is:
<?php require 'other/index2.php'; ?>
Then create e:/myweb/other/index2.php
The content is:
<?php
echo $_SERVER["SCRIPT_FILENAME"];
echo __FILE__;
?>
Then visit http://127.0.0.1/index.php, the output is as follows:
e:/myweb/index.php                         ---- ---------------The absolute path and file name of the currently executing program
E:\myweb\other\index2.php             ---------------- ---The absolute path and file name of the original file (included file)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324466650&siteId=291194637