我在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
现在如何在PHP中的file_exists
中编写它来知道文件是否存在?
最佳答案
看看__DIR__
持续的。最大的好处是这个常量与操作系统无关,因此它可以在 Linux、Window、macOS 以及几乎任何其他运行 PHP 的东西上运行。
if (!file_exists(__DIR__ . '/relative/path/to/config_manifest.ini')
关于php - 如何获取Linux系统的具体路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50372817/