php - 如何获取Linux系统的具体路径
问题描述
我已经在 Windows 机器上开发了代码,所以代码如下
if (!file_exists('C:/xampp/htdocs/Collector/config_manifest.ini')){
$ec->writeErrorMessage("manifest config file not found");
exit;
}
移动到 Linux 系统的代码和我通过 FTP 找到的路径/var/www/html/php/Collector/config_manifest.in
现在是如何file_exists
在 PHP 中编写它以知道该文件是否存在?
解决方案
看看__DIR__
常数。最大的好处是这个常量是独立于操作系统的,所以它可以在 Linux、Window、macOS 以及几乎任何其他运行 PHP 的东西上运行。
if (!file_exists(__DIR__ . '/relative/path/to/config_manifest.ini')
推荐阅读
- android - How I can check in my android app that, is microcontroller and firebase are connected or not?
- c++ - Set console screen size and screen buffer by rows and columns
- java - 尝试设置列表时的 typeMismatch.java.util.List
- perl - Google Maps API returned status 'REQUEST_DENIED' in perl
- email - 我想将我的 gsuit 非管理员帐户设为 noreply 帐户
- xslt - How to perform intersection in nodeset using xpath 2.0
- session - Neo4jTransactionManager 的替代方案以尊重 REQUIRES_NEW 隔离
- bash - 我如何在 bash 中循环而不重复值对?
- html - 如何在没有任何标签的div之间获取文本?15
- c++ - 如何将文件中的字符放入二维向量中?