Do you have access to $_SERVER['SCRIPT_NAME']
? If you do, doing:
dirname($_SERVER['SCRIPT_NAME']);
Should work. Otherwise do this:
In PHP < 5.3:
substr(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT']));
Or PHP >= 5.3:
substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT']));
You might need to realpath()
and str_replace()
all
to /
to make it fully portable, like this:
substr(str_replace('\', '/', realpath(dirname(__FILE__))), strlen(str_replace('\', '/', realpath($_SERVER['DOCUMENT_ROOT']))));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…