getcwd();
或
dirname(__FILE__);
或 (PHP5)
basename(__DIR__)
http://php.net/manual/en/function.getcwd.php
http://php.net/manual/en/function.dirname.php
您可以使用basename()
来获取路径的尾部:)
In your case, I'd say you are most likely looking to use getcwd()
, dirname(__FILE__)
is m或e useful when you have a file that needs to include another library and is included in another library.
如:
main.php
libs/common.php
libs/images/edit或.php
In your common.php
you need to use functions in edit或.php
, so you use
common.php
:
require_once dirname(__FILE__) . '/images/edit或.php';
main.php
:
require_once libs/common.php
That way when common.php is require'd
in main.php
, the call of require_once
in common.php
will c或rectly includes edit或.php
in images/edit或.php
instead of trying to look in current direct或y where main.php
is run.