這裡 提出了一種解決方式:
// let's make sure the $_SERVER['DOCUMENT_ROOT'] variable is set
if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['SCRIPT_FILENAME'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['PATH_TRANSLATED'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
// $_SERVER['DOCUMENT_ROOT'] is now set - you can use it as usual...
但是在 DOS 模式下(為了使用 Windows 排程功能)使用命令列執行時仍會顯示路徑錯誤。
可以使用這個方式:
require_once(dirname(__FILE__)."/../../test.php");
沒有留言:
張貼留言