$_SERVER['SCRIPT_FILENAME'] -------> 当前执行程序的绝对路径及文件名
__FILE__ -------> 原始文件 (被包含文件) 的绝对路径及文件名
eg:
假设 web 根目录是 e:/myweb
先建立 e:/myweb/index.php
内容是:
<?php require 'other/index2.php'; ?>
再建立 e:/myweb/other/index2.php
内容是:
- <?php
- echo $_SERVER["SCRIPT_FILENAME"];
- echo __FILE__;
- ?>
然后访问 http://127.0.0.1/index.php, 输出结果如下:
E:/myweb/index.php ------------------- 当前执行程序的绝对路径及文件名
E:\myweb\other\index2.php ------------------- 原始文件 (被包含文件) 的绝对路径及文件名
php$_SERVER['SCRIPT_NAME']和__FILE__的区别
来源: http://www.bubuko.com/infodetail-2604654.html