开发者

php: get the directory in which resides a file [duplicate]

开发者 https://www.devze.com 2023-03-01 13:54 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: PHP: let a file return its own directory.
This question already has answers here: Closed 11 years ago.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消