【问题标题】:file_exists returns true on Windows for Linux pathfile_exists 在 Windows for Linux 路径上返回 true
【发布时间】:2016-05-15 08:57:06
【问题描述】:

我有一个奇怪的问题。

file_exists('/home/1/w/bla/www/bla')

我在 Windows 服务器上,这返回 true! Windows 服务器上显然不存在该目录。有人知道为什么吗?

【问题讨论】:

  • realpath('/home/1/w/bla/www/bla') 的回报是什么?
  • 啊哈!它是 C:\home\... 如果脚本没有退出,它应该创建目录,但只能在 linux 服务器上创建,但看起来它也设法在 Windows 上创建了该目录。如果路径不是 100% 正确,我确信这些函数会失败(这意味着它必须以“C:\”开头)
  • PHP 足够聪明,可以在 windows 和 linux 之间转换路径
  • 但是有什么办法可以防止这种行为吗?我不希望 mkdir('/dfh/sdfkjh/') 在 Windows 上工作。
  • 你不能真正阻止它工作,因为它是一种本机行为,但你可以添加一个 if 语句来检查你是在 linux 还是 windows 上,然后调整你的路径 stackoverflow.com/questions/5879043/…

标签: php path


【解决方案1】:

PHP 足够聪明,可以在 Windows 上转换 linux 路径,因此 file_exists('/home/1/w/bla/www/bla') 将检查文件 c:\home\1\w\bla\www\bla 是否存在

【讨论】:

    猜你喜欢
    • 2013-01-19
    • 2021-03-25
    • 2016-08-01
    • 2016-05-28
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多