perchten / truepath
替换PHP的极不稳定的realpath()
1.0.0
2014-05-13 22:27 UTC
This package is not auto-updated.
Last update: 2024-09-14 16:24:02 UTC
README
替换PHP的极不稳定的realpath()
用法
安装
通过Composer
Truepath可在Packagist上找到(perchten/truepath),因此可以通过Composer进行安装。
在您的composer.json
中添加以下内容
{
"require": {s
"perchten/truepath": "1.*"
}
}
直接包含
从GitHub克隆或下载,然后直接在代码中包含
require_once "path/to/truepath/truepath.php"
代码
它只是一个简单的函数,因此它不是命名空间化的,而是作为一个全局可用的函数加载。所以只需使用
$truepath = truepath("some/possible/path")
与PHP的realpath不同,此函数在出错时不会返回false;它返回一个尽可能解决这些问题的路径。
这不会在包括UNC和URL在内的网络资源上工作。它仅适用于本地文件系统。
致谢
所有功劳归功于Christian,他在这个StackOverflow问题上。我只是将此放在一些仓库中以方便访问。