我在另一个文件(带有一堆其他函数)中有一个 PHP 函数,它返回一个文件的地址。调用文件 commonFunctions.php。见下文。
function filePath($fPath) {
$cutPath = str_replace("/var/www","http://myinternalwebsite",$fPath);
return $cutPath;
}
当我想要另一个文件的地址时,我只需通过使用include $_SERVER['DOCUMENT_ROOT'] . "/commonFunctions.php
和调用来包含我的函数文件filePath(dirname(__FILE__))
。结果类似于http://myinternalwebsite.com/myScript.php
.
有没有办法放置dirname(__FILE__)
在我的函数中,所以我所要做的就是通过键入 filePath() 来引用该函数?我尝试做类似以下的事情
function filePath() {
$cutPath = str_replace("/var/www","http://myinternalwebsite",dirname(__FILE__));
return $cutPath;
}
但这显然给了我 commonFunctions.php 文件的地址,而不是我在其中调用函数的文件。
提前致谢。
-安东尼