Possible Duplicate:
PHP: let a file return its own directory.
Hi
I have a file located in a directory like this:
C:\wamp\www\site\modules\file.php
How can I get the current directory of file.php from within that script? This directory should look like modules
in this case
I needs this directory name to build 开发者_如何学运维a URL path to a css file from the same directory.
dirname(__FILE__) . "/" . basename(__DIR__)
or
dirname(__FILE__)
You can take advantage of pathinfo.
$path_parts = pathinfo('C:\wamp\www\site\modules\file.php');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
精彩评论