首页 > 解决方案 > 如何获取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 中编写它以知道该文件是否存在?

标签: phplinux

解决方案


看看__DIR__常数。最大的好处是这个常量是独立于操作系统的,所以它可以在 Linux、Window、macOS 以及几乎任何其他运行 PHP 的东西上运行。

if (!file_exists(__DIR__ . '/relative/path/to/config_manifest.ini')

推荐阅读