【发布时间】:2015-01-08 17:43:07
【问题描述】:
我在另一个文件(带有一堆其他函数)中有一个 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 文件的地址,而不是我在其中调用函数的文件。
提前致谢。
-安东尼
【问题讨论】:
-
没有办法按照您的要求进行操作。如果您正在尝试解决更普遍的问题,也许说明该问题会激发某人能够对替代方法发表评论。
标签: php function filepath dirname