I was trying to get path current path in PHP. I tried looking though phpinfo();
, but I haven't found any interesting values which could be used to get path to my script. There is no nice values which I used on Linux, like $_SERVER["PWD"]
.
Now I'm wondering how I'm supposed to find current path. Maybe some function will work... I really have 开发者_运维技巧no idea. Because I don't want to hardcode path to script.
getcwd()
is what you are looking for.
It's not entirely clear whether you mean the current working directory, or the path to the current script. For the working directory, see @Taze's answer.
For the current script, the __FILE__
magic constant will give you the full filesystem path to the current file.
Note that these constants take "current file" literally: If you include a file and call __FILE__
there, it will show the included file's path.
The getcwd()
method will return the current working directory on success.
<?php
echo getcwd() . "\n";
?>
精彩评论