包含PHP脚本的脚本路径?

时间:2009-11-02 21:54:20

标签: php path relative

有没有办法实现以下目标?

在我的/www/var/public_html/index.php文件中,我有这个

<?php include('database/connect.php'); ?>

然后在/www/var/public_html/database/connect.php中,我想做类似的事情

<?php

$my_path = get_path_of_current_script(); // should not be path of index.php
echo $my_path;
// should print
// /www/var/public_html/database
?>

我不希望$ my_path打印/ www / var / public_html /

是否有PHP函数可以执行此操作?

1 个答案:

答案 0 :(得分:6)

$my_path = dirname(__FILE__);
相关问题