我的网站上的文件夹中有一个php页面.
我需要将当前目录的名称添加到变量中,例如:
$myVar = current_directory_name;
Run Code Online (Sandbox Code Playgroud)
这可能吗?
And*_*ong 228
getcwd();
Run Code Online (Sandbox Code Playgroud)
http://php.net/manual/en/function.getcwd.php
http://php.net/manual/en/function.dirname.php
您可以使用basename()获取路径的尾部:)
在您的情况下,我会说您最有可能使用getcwd(),dirname(__FILE__)当您有一个需要包含另一个库并包含在另一个库中的文件时更有用.
例如:
dirname(__FILE__);
Run Code Online (Sandbox Code Playgroud)
在common.php你的需要使用函数editor.php,所以你使用
的common.php:
basename(__DIR__)
Run Code Online (Sandbox Code Playgroud)
main.php
main.php
libs/common.php
libs/images/editor.php
Run Code Online (Sandbox Code Playgroud)
这样,当的common.php是common.php在main.php,的通话require'd中main.php会包含正确require_once的common.php,而不是试图在当前目录下查找其中editor.php运行.
yes*_*nik 14
仅获取执行脚本的目录的名称:
//Path to script: /data/html/cars/index.php
echo basename(dirname(__FILE__)); //"cars"
Run Code Online (Sandbox Code Playgroud)
小智 11
例如
Your Path = /home/serverID_name/www/your_route_Dir/
THIS_is_the_DIR_I_Want
一个工作的灵魂:
$url = dirname(\__FILE__);
$array = explode('\\\',$url);
$count = count($array);
echo $array[$count-1];
Run Code Online (Sandbox Code Playgroud)
小智 10
echo basename(__DIR__); will return the current directory name only
echo basename(__FILE__); will return the current file name only
Run Code Online (Sandbox Code Playgroud)
小智 7
其实我找到了最好的解决方案如下:
$cur_dir = explode('\\', getcwd());
echo $cur_dir[count($cur_dir)-1];
Run Code Online (Sandbox Code Playgroud)
如果您的目录是www\var\path\Current_Path
然后返回Current_path
| 归档时间: |
|
| 查看次数: |
248800 次 |
| 最近记录: |