Typically, PHP $_server[' script_filename ' and __file__ will return the full path (absolute path) and file name of the PHP file:
<?phpecho ' script_filename: ', $_server[' script_filename '];echo ' <br/> '; Echo ' __file__ is: ', __FILE__;// Output?> in included Files
Copy the above test code to test.php and access the file (http://127.0.0.1/php/test.php) to get the following result:
Tip: In the Windows platform test, get the results as shown above there may be subtle differences in path separators.
$_server[' Script_filename ') differs from __file__
Although $_server[' Script_filename ' is very similar to __file__, there are subtle differences when files are included in include or require.
Copy the above test code to E:\web\html\php\common\inc.php and include the inc.php in the test.php file just now:
<?phpinclude ' common/inc.php ';? >
When you access the test.php file again, the output:
The difference between the two is that$_server[' script_filename ' reflects the absolute path and file name of the current executing program, and __file__ reflects the absolute path and file name of the original file (the contained file).
It can be understood that$_server[' script_filename ' is output only for the absolute path and file name of the executable files, regardless of which file is written.
__FILE__ write in which file, output the absolute path and file name of which file.
Reprinted: 53402477
The difference between PHP $_server[' Script_filename ' and __file__